JSON column formatting to preview SharePoint Online file on mouse hover

SharePoint developers can use JSON to format columns, views and customize list form.

Let us look at an example to preview the file content using a hover card, when the user moves the mouse over the file name (or any other field of your choice).

We are going to setup a new column "preview" (single line of text) and apply JSON formatting to this column.

  1. Navigate to your list/library.
  2. Select the column in view.
  3. Click Column settings --> Format this column.
  4. SharePoint JSON column formatting
    SharePoint JSON column formatting
  5. This will open a pane in the right section of screen 'Format preview column'.
  6. Copy and paste below JSON in the text box.
  7. {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
      "elmType": "img",
      "attributes": {
        "src": "@thumbnail.medium"
      "style": {
        "display": "block",
        "margin": "0 auto",
        "max-height": "100px"
      "customCardProps": {
        "openOnEvent": "hover",
        "isBeakVisible": true,
        "formatter": {
          "elmType": "img",
          "attributes": {
            "src": "@thumbnail.200x400"
          "style": {
            "max-height": "400px"
  8. Click Preview and make adjustments, if required.
  9. Click 'Save' once comfortable with the hover card.

This is how the output will look. When user moves mouse and hover over the 'preview' column value of the file in Document Library, the hover card will popup and shows the contents of the file. You can adjust the height/width and other style parameters for the card.
Also note that we are showing a small thumbnail preview of the file in the same 'preview' column.

SharePoint file hover preview using JSON
SharePoint file hover preview using JSON

Have Questions? Post them here!

Hello there!,

You are using AdBlocker!

I am an independent developer trying to help fellow developers and students to resolve issues faced on a day-to-day basis, we 'Code to Care' . There is a lot of expenses involved in hosting and managing a website that's the reason we have ads.

A humble request to you to disable adBlocker on Code2care.org and support us pay our bills.

Cod2care - Line's of code for change.

To see contents reload page after unblocking
Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities. Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Video Tutorials, Code Snippets, Tips-n-tricks, How Tos, Blogs, Articles, etc. on various platforms like Windows, Mac, Linux, Mobile platforms, etc. Technologies/Languages like Java, Objective-C, PHP, .Net, Android, SharePoint, jQuery, HTML, CSS, etc.