Back to column formats
Column formattingSharePoint Online

Multiple thumbnail

This tutorial will help you create a multiple thumbnail through images URLs listed in a multiple choice column.

screenshot of the sample
Sample preview · View original image

Copy. Apply. Make it yours.

Get this format

2 definitions

Review the requirements below, then paste this JSON into the matching formatting panel. Show me where.

Use your list's internal column names and replace any tenant-specific URLs or flow IDs. Formatting is presentation, not a way to secure data.

Column formatting
Download JSON
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "min-width": "730px",
    "height": "=if(Number(@now) < Number([$VIEWTIME]) && [$LASTURL] != '', '600px', 'auto')",
    "flex-wrap": "nowrap",
    "flex-direction": "row",
    "display": "flex",
    "align-items": "flex-start",
    "justify-content": "flex-start",
    "box-sizing": "border-box"
  },
  "children": [
    {
      "elmType": "div",
      "style": {
        "position": "relative",
        "top": "10px",
        "z-index": "0",
        "width": "100%",
        "flex-wrap": "wrap",
        "flex-direction": "row",
        "display": "=if(Number(@now) < Number([$VIEWTIME]) && [$LASTURL] != '', 'none', 'flex')",
        "align-items": "flex-start",
        "justify-content": "flex-start",
        "margin-bottom": "10px",
        "box-sizing": "border-box"
      },
      "children": [
        {
          "forEach": "choiceIterator in @currentField",
          "elmType": "div",
          "customRowAction": {
            "action": "setValue",
            "actionInput": {
              "LASTURL": "[$choiceIterator]",
              "VIEWTIME": "=Number(@now) + 5000"
            }
          },
          "style": {
            "position": "relative",
            "display": "flex",
            "align-items": "center",
            "justify-content": "center",
            "border-radius": "4px",
            "box-sizing": "border-box",
            "margin": "6px 12px 12px 6px",
            "cursor": "pointer"
          },
          "children": [
            {
              "elmType": "img",
              "style": {
                "display": "flex",
                "align-self": "flex-start",
                "box-sizing": "border-box",
                "border-radius": "4px",
                "max-width": "240px",
                "max-height": "120px",
                "border": "solid 2px grey",
                "object-fit": "contain",
                "box-shadow": "3px 1px 4px #a3a3a2"
              },
              "attributes": {
                "src": "[$choiceIterator]",
                "title": "[$choiceIterator]"
              }
            }
          ]
        }
      ]
    },
    {
      "elmType": "div",
      "style": {
        "display": "=if(Number(@now) < Number([$VIEWTIME]) && [$LASTURL] != '', 'flex', 'none')",
        "align-items": "center",
        "justify-content": "center",
        "flex-wrap": "nowrap",
        "flex-direction": "column",
        "position": "relative",
        "box-sizing": "border-box",
        "width": "960px",
        "height": "600px",
        "border": "solid 2px #974b8b",
        "border-radius": "5px",
        "background-color": "white"
      },
      "children": [
        {
          "elmType": "div",
          "style": {
            "position": "absolute",
            "display": "flex",
            "justify-content": "flex-end",
            "align-items": "center",
            "top": "0",
            "width": "956px",
            "height": "30px",
            "background-color": "white"
          },
          "children": [
            {
              "elmType": "a",
              "style": {
                "box-sizing": "border-box",
                "padding-bottom": "4px",
                "display": "flex",
                "align-items": "center",
                "justify-content": "center",
                "font-size": "18px",
                "font-weight": "bold",
                "width": "30px",
                "height": "30px",
                "margin-right": "6px",
                "text-decoration": "none",
                "cursor": "pointer"
              },
              "attributes": {
                "class": "sp-css-color-LightPurpleText sp-css-backgroundColor-LightPurpleText--hover ms-fontColor-white--hover",
                "href": "[$LASTURL]",
                "target": "_blank",
                "title": "View in your browser",
                "iconName": "NavigateExternalInline"
              }
            },
            {
              "elmType": "div",
              "customRowAction": {
                "action": "setValue",
                "actionInput": {
                  "LASTURL": ""
                }
              },
              "style": {
                "box-sizing": "border-box",
                "padding-bottom": "2px",
                "display": "flex",
                "align-items": "center",
                "justify-content": "center",
                "font-size": "16px",
                "font-weight": "bold",
                "width": "30px",
                "height": "30px",
                "text-decoration": "none",
                "cursor": "pointer"
              },
              "attributes": {
                "class": "sp-css-color-WhiteText sp-css-backgroundColor-LightPurpleText",
                "title": "Close window",
                "iconName": "ChromeClose"
              }
            }
          ]
        },
        {
          "elmType": "img",
          "style": {
            "max-width": "900px",
            "max-height": "570px",
            "object-fit": "contain",
            "box-shadow": "3px 1px 4px #a3a3a2"
          },
          "attributes": {
            "src": "[$LASTURL]"
          }
        }
      ]
    }
  ]
}

From the contributor

How to use this sample

Summary

This tutorial will help you create multiple thumbnails through images URLs listed in a multiple choice column.

screenshot of the sample

To achieve this result, you can implement one of the following column formatting options:

1. Basic thumbnail: each URL is displayed with its own miniature and a little button to open each image through your default web browser.

2. Advanced thumbnail: each URL is displayed with its own miniature and each image can be viewed in a larger version through a temporary UI window. This window contains a command bar to open an image through your default web browser.

NOTE: an image URL should point directly to a picture file format, such as jpg, png, gif, etc. Furthermore, each image URL can come from an allowed external domain or it should be accessible by other users if stored in SharePoint.

Examples of images URLs are:

View requirements

Column width and user interface

Both samples illustrated below have a column min-width of 730px, to allow an optimal user interface both for a list view and the OOTB Microsoft Lists form. If your multiple thumbnail appears as partially cut, select the right edge of column header, drag to the right and increase its width. Save your view to keep current column settings.

Sample illustration


1) Basic thumbnail: how to

The basic thumbnail template requires only one multiple choice column, with custom values allowed or not. After creating a multiple choice column, apply the JSON code available here.

Sample illustration

2) Advanced thumbnail: how to

Sample illustration

The advanced thumbnail template requires users to have editing permission (eg. in a project team members) and the following columns, including their exact names with capital letters. The exact names are required only for columns creation, so that they'll match with the internal names the JSON code refers to. Therefore, all the columns listed below can be renamed later:

COLUMN NAME COLUMN TYPE ADDITIONAL INFORMATION
MULTIPLETHUMBNAIL Multiple choice Each image URL is a corresponding option of this column
LASTURL Multiple lines of text This column keeps track temporarily of an image URL, when a user clicks on a miniature to open a larger window
VIEWTIME Single line of text This column keeps track of the current date and time to perform an if condition temporarily true, so that a larger preview window works properly on click

After creating the 3 columns reported above, format the MULTIPLETHUMBNAIL column with the JSON code available here.

Here is an illustration of the large preview window:

Sample illustration

Custom hovercards and app limitation

Images lightboxes are currently not supported by Microsoft Lists, since hovercards are not designed to recognize an iteratorName of each image in an array, based on a forEach property.

Temporary preview window: behind the scenes

If you are wondering what's happening when a user clicks on a miniature, here is a process illustration about how a temporary window works in Microsoft Lists:

Sample illustration

Sample

Solution Author(s)
multi-choice-thumbnail.json Federico Sapia
multi-choice-thumbnail-advanced.json Federico Sapia

Version history

Version Date Comments
1.0 January 19, 2024 Initial release

Disclaimer

THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.