Back to column formats
Column formattingSharePoint Online

Star Rating

This sample demonstrates changing the value of a number column to a star rating.

Star Rating formatting preview
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": {
    "display": "flex",
    "flex-direction": "row",
    "white-space": "nowrap"
  },
  "children": [
    {
      "elmType": "div",
      "style": {
        "font-size": "24px",
        "position": "relative"
      },
      "children": [
        {
          "elmType": "div",
          "txtContent": "★★★★★",
          "attributes": {
            "class": "ms-fontColor-neutralTertiaryAlt"
          }
        },
        {
          "elmType": "div",
          "txtContent": "★★★★★",
          "style": {
            "position": "absolute",
            "top": "0",
            "overflow": "hidden",
            "max-width": "100%",
            "width": "=if(@currentField < 0, '0px',(@currentField / 5) * 100 + '%')",
            "color": "#FFB951"
          }
        }
      ]
    },
    {
      "elmType": "div",
      "txtContent": "@currentField.displayValue",
      "style": {
        "margin-left": "10px",
        "font-size": "16px"
      }
    }
  ]
}

From the contributor

How to use this sample

Summary

This sample demonstrates changing the value of a number column to a star rating.

  • number-star-rating.json uses the theme color of the site as the color of the star.
  • number-star-rating-custom-color.json uses the HTML color code as the the color of the star, and in the sample, #FFB951 is set.

screenshot of the sample

You can also change the ★ set in txtContent to ♥ or ♡ to make it a heart rating.

screenshot of the heart sample

View requirements

This format can be applied to a Number column (the format expects values from 0-5)

Sample

Solution Author(s)
number-star-rating.json Tetsuya Kawahara
number-star-rating-custom-color.json Tetsuya Kawahara

Version history

Version Date Comments
1.0 June 11, 2022 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.