Background
I have seen people requesting this feature in the past where we need to display file preview thumbnail for a document in the SharePoint library. We are getting some awesome features in SharePoint Online nowadays, and very frequently as well. In this article, we will learn about how to display thumbnail or preview for any file type in SharePoint document library using the column formatting feature. This article is part of a series to learn and know the howabout of SharePoint column formatting.
First, let us set up our Document library with the required column.
Step 1
Create a column with name 'Preview' in any of Document Library.
Column Type - Calculated column
Enter Formula as ="" (just empty string using double quotation mark)
Step 2
Upload some dummy document with a different file type.
Step 3
Now, let us format this column. We need to Edit the column from the Document Library settings.
An alternate and fast way is to use modern UI experience to format this column (the below screenshot depicts the same).
Step 4 - Add below JSON.
Here, we are creating an image DOM element and using @thumbnail.medium as src. @thumbnail is the default property which is being used here for file preview.
- {
- "$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": "42px"
- }
- }
So based on file type it will create file preview automatically and displays in view. Please note that pdf, docx, pptx and around other 170 file types are supported (ref - video).
This concludes our learning on how to use @thumbnail with column formatting for file preview in list view.
Now, let us see what different attributes are available with @thumbnail which can be used. Depending on how you want to format your column you can use a different pattern too.
pattern is @thumbnail.property
| @thumbnail.small | auto small sized thumbnail |
| @thumbnail.medium | auto medium sized thumbnail |
| @thumbnail.large | auto large sized thumbnail |
| @thumbnail.200 | custom - 200 width and 200 height |
| @thumbnail.200x100 | custom - 200 width and 100 height |
A more advanced example is below, here we are adding title attribute so that on hover of preview image we get some tooltip. It also handles a scenario where if the content type is a folder, it will set the title attribute to empty string but if it is anything else, it will be a simple 'Hey' message.
- {
- "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
- "elmType": "div",
- "attributes": {
- "title": "=if([$ContentType] == 'Folder','','Hey')"
- },
- "children":[{
- "elmType": "img",
- "attributes": {
- "src": "@thumbnail.medium"
- },
- "style": {
- "display": "block",
- "margin": "0 auto",
- "max-height": "42px"
- }
- }]}
That's it for now. Thanks for reading.
This article is inspired by the contribution of @theChrisKent at the link.
P.S - I did not find a list of supported file formats to preview. If anyone has any reference to the list of supported file formats in column formatting, please share in the comments section.

Jérôme HaguetPosted Mar 12, 2021, 2:41 PM
Here is a list for "previewing" file type, I guess it applies to preview and thumbnail. https://support.microsoft.com/en-us/office/file-types-supported-for-previewing-files-in-onedrive-sharepoint-and-teams-e054cd0f-8ef2-4ccb-937e-26e37419c5e4
APosted Feb 17, 2021, 4:27 PM
This is great, thank you.. It only works when QuickEdit mode is off. When I click Quick Edit to edit data, the image thumbnails appear white and blank. Is there a way in the JSON to get it to work with both Quick Edit on?
Rushil ShahPosted Jun 23, 2020, 4:52 AM
Good article but instead of column formatting you can also add new column called "Thumbnail" and type of this column can be single line of text which will display the preview of the supported document.
Siddharth VaghasiaPosted Sep 23, 2019, 9:55 PM
Column formatting works only in SPOnline.
Brett AndoPosted Sep 23, 2019, 5:40 PM
What version of SharePoint can the thumbnail preview be added to? SP2016, SP2019, SPOnline?