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!



Recent Posts:




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, How Tos, Blogs, Articles, etc.