SharePoint JSON List Formatting Training

Introduction and Prerequisites

Check here first before you begin.

» read more

You should know:

You should also know:

Before you get started, create your own practice SharePoint site. This is your own dedicated site where you will create and update lists used in training. In each training module, you will make updates to SharePoint lists, write JSON code, then apply it to lists.

All code will work with SharePoint Online and SharePoint Server Subscription (2022+). SharePoint 2019 and ealier is not supported.


Resources

Get the most out of JSON coding use these resources.

» read more

Choice Background Colors

Apply background colors to a choice field according to value.

Fields:

  • Choice (Values: Not Started, In Progress, On Hold, Canceled, Complete)
Instructions
This template will produce this HTML structure:
FIELD CONTENT

1. Begin with column formatting schema:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div"
}
copy to editor

2. Add a child div:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "div",      
      "txtContent": "@currentField",
      "style": {
        "margin": "auto"
      }
    }
  ]
}
copy to editor

3. Use if condition checks to set the background color:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "background-color": "=if(@currentField == 'Not Started','cyan','') + if(@currentField == 'In Progress','orange','') + if(@currentField == 'On Hold','pink','') + if(@currentField == 'Canceled','LightGray','') + if(@currentField == 'Complete','lime','')" 
  },
  "children": [
    {
      "elmType": "div",      
      "txtContent": "@currentField",
      "style": {
        "margin": "auto"
      }
    }
  ]
}
copy to editor

4. Apply additional styles to the parent div:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "background-color": "=if(@currentField == 'Not Started','cyan','') + if(@currentField == 'In Progress','orange','') + if(@currentField == 'On Hold','pink','') + if(@currentField == 'Canceled','LightGray','') + if(@currentField == 'Complete','lime','')", 
    "color": "black",
    "font-size": "20px",
    "font-family": "arial",
    "border": "1px solid black",
    "border-radius": "7px"
  },
  "children": [
    {
      "elmType": "div",      
      "txtContent": "@currentField",
      "style": {
        "margin": "auto"
      }
    }
  ]
}
copy to editor
  • Apply the code to your field.
  • Try adjusting colors and font.
  • Try adjusting the border.
  • See a live preview using the link below.

Inline Edit

Enable inline editing for a specific field.

Fields:

  • Text, Number, Date, Choice, Person or Lookup
Instructions
This template will produce this HTML structure:
FIELD CONTENT

1. Begin with column formatting schema:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div"
}
copy to editor

2. Add attributes:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "inlineEditField": "@currentField",
  "txtContent": "@currentField"
}
copy to editor

3. Add styles:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "inlineEditField": "@currentField",
  "txtContent": "@currentField",
  "style": {
    "display": "flex",
    "width": "98%",
    "border": "1px solid transparent",
    "--inline-editor-border-color": "LimeGreen",
    "cursor": "pointer",
    "padding": "11px 0px 11px 2px",
    "margin-left": "0px"
  }
}
copy to editor
  • Apply the code to your field.
  • Try adjusting the hover color.
  • Try adjusting the padding.
  • See a live preview using the link below.

Date Highlighting

Apply background colors to a date field according to whether date is future, past or today.

Fields:

  • Date
Instructions
This template will produce this HTML structure:
FIELD CONTENT

1. Begin with column formatting schema:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div"
}
copy to editor

2. Add a child div:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "div",      
      "txtContent": "@currentField",
      "style": {
        "margin": "auto"
      }
    }
  ]
}
copy to editor

3. Compare the date and change the background color accordingly:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "background-color": "=if(toDateString(@now) == toDateString(@currentField),'LightYellow',if(@currentField < @now,'LavenderBlush','Lime'))"
  },
  "children": [
    {
      "elmType": "div",      
      "txtContent": "@currentField",
      "style": {
        "margin": "auto"
      }
    }
  ]
}
copy to editor

4. Add additional styles to the parent div:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "background-color": "=if(toDateString(@now) == toDateString(@currentField),'LightYellow',if(@currentField < @now,'LavenderBlush','Lime'))",  
    "color": "black",
    "font-size": "14px",
    "font-family": "arial",
    "border": "1px solid Black",
    "border-radius": "7px"
  },
  "children": [
    {
      "elmType": "div",      
      "txtContent": "@currentField",
      "style": {
        "margin": "auto"
      }
    }
  ]
}
copy to editor

5. Hide the output if there is no date:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "background-color": "=if(toDateString(@now) == toDateString(@currentField),'LightYellow',if(@currentField < @now,'LavenderBlush','Lime'))",  
    "color": "black",
    "font-size": "14px",
    "font-family": "arial",
    "border": "1px solid Black",
    "border-radius": "7px",
    "display": "=if(@currentField,'flex','none')"
  },
  "children": [
    {
      "elmType": "div",      
      "txtContent": "@currentField",
      "style": {
        "margin": "auto"
      }
    }
  ]
}
copy to editor
  • Apply the code to your field.
  • Try adjusting colors and font.
  • Try adjusting the border.
  • See a live preview using the link below.

Library Thumbnail

Display a thumbnail preview image for files in a library. Opens file on click.

Fields:

  • Placeholder Field
Instructions
This template will produce this HTML structure:

1. Begin with column formatting schema:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div"
}
copy to editor

2. Add a child button with an image inside:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "button",
      "children": [
        {
          "elmType": "img"
        }
      ]
    }
  ]
}
copy to editor

3. Add image source attribute and styling:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "button",
      "children": [
        {
          "elmType": "img",
          "attributes": {
            "src": "@thumbnail.100"
          },
          "style": {
            "display": "inline-block",
            "height": "100%",
            "vertical-align": "middle"
          }
        }
      ]
    }
  ]
}
copy to editor

4. Add a click action to the button and give it a hover border:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "button",
      "customRowAction": {
        "action": "defaultClick"
      },
      "attributes": {
        "class": "ms-borderColor-black ms-borderColor-greenLight--hover"
      },	  
      "children": [
        {
          "elmType": "img",
          "attributes": {
            "src": "@thumbnail.100"
          },
          "style": {
            "display": "inline-block",
            "height": "100%",
            "vertical-align": "middle"
          }
        }
      ]
    }
  ]
}
copy to editor

5. Add styling to the button element:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "button",
      "customRowAction": {
        "action": "defaultClick"
      },
      "attributes": {
        "class": "ms-borderColor-black ms-borderColor-greenLight--hover"
      },
      "style": {
        "overflow": "hidden",
        "cursor": "pointer",
        "padding": "1px",
        "background-color": "lightgray"
      },	  
      "children": [
        {
          "elmType": "img",
          "attributes": {
            "src": "@thumbnail.100"
          },
          "style": {
            "display": "inline-block",
            "height": "100%",
            "vertical-align": "middle"
          }
        }
      ]
    }
  ]
}
copy to editor
  • Apply the code to your placeholder field.
  • Try adjusting the size.
  • Try adjusting the colors including background and border.
  • See a live preview using the link below.

Row Formatting

Adjust the background color, borders and font size styling for rows of data.

Fields:

  • Any field type
Instructions

1. Begin with view formatting schema:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json"
}
copy to editor

2. Add additionalRowClass and adjust font size:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
  "additionalRowClass": "ms-font-m"
}
copy to editor

3. Set the text color

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
  "additionalRowClass": "ms-font-m ms-fontColor-black"
}
copy to editor

4. Set the selected row background color:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
  "additionalRowClass": "='ms-font-m ms-fontColor-black ' + if(@isSelected,'sp-css-backgroundColor-BgGold','')"
}
copy to editor

5. Set the row background color and alternating row background color:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
  "additionalRowClass": "='ms-font-m ms-fontColor-black ' + if(@isSelected,'sp-css-backgroundColor-BgGold',if(@rowIndex % 2 == 0,'sp-css-backgroundColor-BgSage20','sp-css-backgroundColor-BgLightBlue')"
}
copy to editor

6. Set row border color and style:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
  "additionalRowClass": "='ms-font-m ms-fontColor-black ' + if(@isSelected,'sp-css-backgroundColor-BgGold',if(@rowIndex % 2 == 0,'sp-css-backgroundColor-BgSage20','sp-css-backgroundColor-BgLightBlue') + ' sp-css-borderBottomColor-DarkBlueText sp-fieldBorderBottomSolid'"
}
copy to editor
  • Apply the code to your view.
  • Try adjusting the font size.
  • Try adjusting the colors for font, background and borders.
  • See a live preview using the link below.

Toggle Button

Display a simple toggle button for use with a yes / no field.

Field:

  • Yes / No Field
Instructions
This template will produce this HTML structure:
BACKGROUND TOGGLE ELEMENT
FOREGROUND TOGGLE ELEMENT

1. Begin with column formatting schema:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div"
}
copy to editor

2. Add div structure:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "display": "flex"
  },
  "children": [
    {
      "elmType": "div"
    },
    {
      "elmType": "div"
    }
  ]
}
copy to editor

3. Add styles:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "display": "flex"
  },
  "children": [
    {
      "elmType": "div",
      "style": {
        "font-size": "60px"
      }
    },
    {
      "elmType": "div",
      "style": {
        "cursor": "pointer",
        "font-size": "60px",
        "margin-left": "-60px"
      }
    }
  ]
}
copy to editor

4. Add a custom row action

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "display": "flex"
  },
  "children": [
    {
      "elmType": "div",
      "style": {
        "font-size": "60px"
      }
    },
    {
      "elmType": "div",
      "style": {
        "cursor": "pointer",
        "font-size": "60px",
        "margin-left": "-60px"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "FIELD REQUIRED": "=if(@currentField,0,1)"
        }
      }
    }
  ]
}
copy to editor

5. Add attributes

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "display": "flex"
  },
  "children": [
    {
      "elmType": "div",
      "attributes": {
        "iconName": "ToggleFilled",
        "class": "=if(@currentField,'ms-fontColor-greenLight','ms-fontColor-gray40')"
      },	  
      "style": {
        "font-size": "60px"
      }
    },
    {
      "elmType": "div",
      "attributes": {
        "iconName": "=if(@currentField,'ToggleRight','ToggleLeft')",
        "class": "=if(@currentField,'ms-fontColor-green','ms-fontColor-gray120') + ' ms-fontColor-yellow--hover'"
      },	  
      "style": {
        "cursor": "pointer",
        "font-size": "60px",
        "margin-left": "-60px"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "FIELD REQUIRED": "=if(@currentField,0,1)"
        }
      }
    }
  ]
}
copy to editor
  • Apply your template to your Yes / No column.
  • Try adjusting colors and font size for different effects.
  • Get other color references using the "live preview" linked below.

Date Input

Display an interactive date input field which increment + / - buttons

Field:

  • Date Field
Instructions
This template will produce this HTML structure:
DATE INPUT

1. Begin with column formatting schema:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div"
}
copy to editor

2. Add a div element surrounded by two buttons:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "button",
      "txtContent": "-"
    },
    {
      "elmType": "div",
      "txtContent": "@currentField"		
    },
    {
      "elmType": "button",
      "txtContent": "+"
    }		
  ]
}
copy to editor

3. Add button actions and enable inline edit:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "button",
      "txtContent": "-",
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "DATE FIELD REQUIRED": "=addDays(@currentField,-1)"
        }
      }
    },
    {
      "elmType": "div",
      "txtContent": "@currentField",
      "inlineEditField": "@currentField"		
    },
    {
      "elmType": "button",
      "txtContent": "+",
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "DATE FIELD REQUIRED": "=addDays(@currentField,1)"
        }
      }
    }
  ]
}
copy to editor

4. Add class attributes to the buttons and add colors:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "button",
      "txtContent": "-",
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "DATE FIELD REQUIRED": "=addDays(@currentField,-1)"
        }
      },
      "attributes": {
        "class": "ms-bgColor-green ms-bgColor-greenLight--hover ms-fontColor-white ms-fontColor-black--hover"
      }
    },
    {
      "elmType": "div",
      "txtContent": "@currentField",
      "inlineEditField": "@currentField"		
    },
    {
      "elmType": "button",
      "txtContent": "+",
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "DATE FIELD REQUIRED": "=addDays(@currentField,1)"
        }
      },
      "attributes": {
        "class": "ms-bgColor-green ms-bgColor-greenLight--hover ms-fontColor-white ms-fontColor-black--hover"
      }
    }
  ]
}
copy to editor

5. Add styles to the buttons:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "button",
      "txtContent": "-",
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "DATE FIELD REQUIRED": "=addDays(@currentField,-1)"
        }
      },
      "attributes": {
        "class": "ms-bgColor-green ms-bgColor-greenLight--hover ms-fontColor-white ms-fontColor-black--hover"
      },
      "style": {
        "cursor": "pointer",
        "font-size": "16px",
        "font-family": "arial",	
        "border": "1px solid Black",
        "width": "22px",
        "height": "22px",
        "border-radius": "7px"
      }
    },
    {
      "elmType": "div",
      "txtContent": "@currentField",
      "inlineEditField": "@currentField"		
    },
    {
      "elmType": "button",
      "txtContent": "+",
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "DATE FIELD REQUIRED": "=addDays(@currentField,1)"
        }
      },
      "attributes": {
        "class": "ms-bgColor-green ms-bgColor-greenLight--hover ms-fontColor-white ms-fontColor-black--hover"
      },
      "style": {
        "cursor": "pointer",
        "font-size": "16px",
        "font-family": "arial",	
        "border": "1px solid Black",
        "width": "22px",
        "height": "22px",
        "border-radius": "7px"
      }
    }
  ]
}
copy to editor

6. Add styles to the date input:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "button",
      "txtContent": "-",
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "DATE FIELD REQUIRED": "=addDays(@currentField,-1)"
        }
      },
      "attributes": {
        "class": "ms-bgColor-green ms-bgColor-greenLight--hover ms-fontColor-white ms-fontColor-black--hover"
      },
      "style": {
        "cursor": "pointer",
        "font-size": "16px",
        "font-family": "arial",	
        "border": "1px solid Black",
        "width": "22px",
        "height": "22px",
        "border-radius": "7px"
      }
    },
    {
      "elmType": "div",
      "txtContent": "@currentField",
      "inlineEditField": "@currentField",
      "style": {
        "border": "1px solid transparent",
        "--inline-editor-border-color": "green",
        "cursor": "pointer",
        "padding": "0px 5px",
        "font-size": "16px",
        "font-family": "arial",
        "text-align": "center",
        "width": "80px",
        "min-height": "22px"
      }	  
    },
    {
      "elmType": "button",
      "txtContent": "+",
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "DATE FIELD REQUIRED": "=addDays(@currentField,1)"
        }
      },
      "attributes": {
        "class": "ms-bgColor-green ms-bgColor-greenLight--hover ms-fontColor-white ms-fontColor-black--hover"
      },
      "style": {
        "cursor": "pointer",
        "font-size": "16px",
        "font-family": "arial",	
        "border": "1px solid Black",
        "width": "22px",
        "height": "22px",
        "border-radius": "7px"
      }
    }
  ]
}
copy to editor
  • Apply the template to your Date Field.
  • Try adjusting colors and other style attributes.
  • Get ideas on tweaking the appearance by using other settings using the live preview below.

Hyperlink Button

Display a hyperlink column as a clickable button.

Field:

  • Hyperlink Field
Instructions
This template will produce this HTML structure:

1. Begin with column formatting schema:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div"
}
copy to editor

2. Style the main div and add child elements:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "display": "=if(@currentField,'flex','none')",
    "justify-content": "center"    
  },
  "children": [
    {
      "elmType": "div",
      "children": [
        {
          "elmType": "div",
          "children": [
            {
              "elmType": "a"			
            }
          ]		  
        }
      ]	  
    }	
  ]
}
copy to editor

2. Style the the second div (outer button):

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "display": "=if(@currentField,'flex','none')",
    "justify-content": "center"    
  },
  "children": [
    {
      "elmType": "div",
      "attributes": {
        "class": "ms-bgColor-blue ms-bgColor-blueLight--hover ms-fontColor-white ms-fontColor-white--hover"
      },
      "style": {
        "font-size": "12px",
        "border": "1px solid black",
        "border-radius": "7px",
        "box-shadow": "2px 2px 2px #999",
        "cursor": "pointer",
        "display": "flex",
        "align-items": "center"
      },	  
      "children": [
        {
          "elmType": "div",
          "children": [
            {
              "elmType": "a"			
            }
          ]		  
        }
      ]	  
    }	
  ]
}
copy to editor

3. Style the the third div (icon):

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "display": "=if(@currentField,'flex','none')",
    "justify-content": "center"    
  },
  "children": [
    {
      "elmType": "div",
      "attributes": {
        "class": "ms-bgColor-blue ms-bgColor-blueLight--hover ms-fontColor-white ms-fontColor-white--hover"
      },
      "style": {
        "font-size": "12px",
        "border": "1px solid black",
        "border-radius": "7px",
        "box-shadow": "2px 2px 2px #999",
        "cursor": "pointer",
        "display": "flex",
        "align-items": "center"
      },	  
      "children": [
        {
          "elmType": "div",
          "attributes": {
            "iconName": "DoubleChevronRight"
          },
          "style": {
            "display": "flex",
            "padding-left": "5px",
            "align-items": "center"
          },		  
          "children": [
            {
              "elmType": "a"			
            }
          ]		  
        }
      ]	  
    }	
  ]
}
copy to editor

4. Add attributes and styles to the anchor element:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "display": "=if(@currentField,'flex','none')",
    "justify-content": "center"    
  },
  "children": [
    {
      "elmType": "div",
      "attributes": {
        "class": "ms-bgColor-blue ms-bgColor-blueLight--hover ms-fontColor-white ms-fontColor-white--hover"
      },
      "style": {
        "font-size": "12px",
        "border": "1px solid black",
        "border-radius": "7px",
        "box-shadow": "2px 2px 2px #999",
        "cursor": "pointer",
        "display": "flex",
        "align-items": "center"
      },	  
      "children": [
        {
          "elmType": "div",
          "attributes": {
            "iconName": "DoubleChevronRight"
          },
          "style": {
            "display": "flex",
            "padding-left": "5px",
            "align-items": "center"
          },		  
          "children": [
            {
              "elmType": "a",
              "attributes": {
                "class": "ms-fontColor-white ms-fontColor-white--hover",		  
                "href": "@currentField"
              },
              "txtContent": "@currentField.desc",
              "style": {
                "display": "flex",
                "font-family": "arial",
                "text-decoration": "none",
                "padding": "3px 5px 3px 22px",
                "margin-left": "-17px"
              }
            }
          ]		  
        }
      ]	  
    }	
  ]
}
copy to editor
  • Apply your template to your Hyperlink Field.
  • Try adjusting colors and other style attributes.
  • Get other color references using the "live preview" linked below.

Star Rating

Display an interactive star rating bar. Rate items from low to high.

Field:

  • Choice (Values: 1,2,3,4,5)
Instructions
This template will produce this HTML structure:
STAR 1 STAR 2 STAR 3 STAR 4 STAR 5

1. Begin with column formatting schema:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div"
}
copy to editor

2. Style the main div and add child elements:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "font-size": "20px",
    "cursor": "pointer"
  },
  "children": [
    {
      "elmType": "span",
      "style": {
        "padding-right": "4px",
        "display": "inline"
      }
    },
    {
      "elmType": "span",
      "style": {
        "padding-right": "4px",
        "display": "inline"
      }
    },
    {
      "elmType": "span",
      "style": {
        "padding-right": "4px",
        "display": "inline"
      }
    },
    {
      "elmType": "span",
      "style": {
        "padding-right": "4px",
        "display": "inline"
      }
    },
    {
      "elmType": "span",
      "style": {
        "padding-right": "4px",
        "display": "inline"
      }
    }	
  ]
}
copy to editor

3. Make each span interactive using customRowAction:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "font-size": "20px",
    "cursor": "pointer"
  },
  "children": [
    {
      "elmType": "span",
      "style": {
        "padding-right": "4px",
        "display": "inline"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "YOUR FIELD NAME": "1"
        }
      }
    },
    {
      "elmType": "span",
      "style": {
        "padding-right": "4px",
        "display": "inline"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "YOUR FIELD NAME": "2"
        }
      }
    },
    {
      "elmType": "span",
      "style": {
        "padding-right": "4px",
        "display": "inline"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "YOUR FIELD NAME": "3"
        }
      }
    },
    {
      "elmType": "span",
      "style": {
        "padding-right": "4px",
        "display": "inline"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "YOUR FIELD NAME": "4"
        }
      }
    },
    {
      "elmType": "span",
      "style": {
        "padding-right": "4px",
        "display": "inline"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "YOUR FIELD NAME": "5"
        }
      }
    }	
  ]
}
copy to editor

4. Show a star icon or empty star icon according to value:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "font-size": "20px",
    "cursor": "pointer"
  },
  "children": [
    {
      "elmType": "span",
      "style": {
        "padding-right": "4px",
        "display": "inline"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "YOUR FIELD NAME": "1"
        }
      },
      "attributes": {
        "iconName": "=if(Number(@currentField) >= 1, 'favoriteStarFill', 'favoriteStar')"
      }
    },
    {
      "elmType": "span",
      "style": {
        "padding-right": "4px",
        "display": "inline"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "YOUR FIELD NAME": "2"
        }
      },
      "attributes": {
        "iconName": "=if(Number(@currentField) >= 2, 'favoriteStarFill', 'favoriteStar')"
      }
    },
    {
      "elmType": "span",
      "style": {
        "padding-right": "4px",
        "display": "inline"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "YOUR FIELD NAME": "3"
        }
      },
      "attributes": {
        "iconName": "=if(Number(@currentField) >= 3, 'favoriteStarFill', 'favoriteStar')"
      }
    },
    {
      "elmType": "span",
      "style": {
        "padding-right": "4px",
        "display": "inline"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "YOUR FIELD NAME": "4"
        }
      },
      "attributes": {
        "iconName": "=if(Number(@currentField) >= 4, 'favoriteStarFill', 'favoriteStar')"
      }
    },
    {
      "elmType": "span",
      "style": {
        "padding-right": "4px",
        "display": "inline"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "YOUR FIELD NAME": "5"
        }
      },
      "attributes": {
        "iconName": "=if(Number(@currentField) >= 5, 'favoriteStarFill', 'favoriteStar')"
      }
    }	
  ]
}
copy to editor

5. Apply different colors according to the field value:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "font-size": "20px",
    "cursor": "pointer"
  },
  "children": [
    {
      "elmType": "span",
      "style": {
        "padding-right": "4px",
        "display": "inline"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "YOUR FIELD NAME": "1"
        }
      },
      "attributes": {
        "iconName": "=if(Number(@currentField) >= 1, 'favoriteStarFill', 'favoriteStar')",
        "class": "=if(Number(@currentField) >= 1, 'ms-fontColor-yellow', 'ms-fontColor-gray40') + ' ms-fontColor-green--hover'"
      }
    },
    {
      "elmType": "span",
      "style": {
        "padding-right": "4px",
        "display": "inline"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "YOUR FIELD NAME": "2"
        }
      },
      "attributes": {
        "iconName": "=if(Number(@currentField) >= 2, 'favoriteStarFill', 'favoriteStar')",
        "class": "=if(Number(@currentField) >= 2, 'ms-fontColor-yellow', 'ms-fontColor-gray40') + ' ms-fontColor-green--hover'"
      }
    },
    {
      "elmType": "span",
      "style": {
        "padding-right": "4px",
        "display": "inline"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "YOUR FIELD NAME": "3"
        }
      },
      "attributes": {
        "iconName": "=if(Number(@currentField) >= 3, 'favoriteStarFill', 'favoriteStar')",
        "class": "=if(Number(@currentField) >= 3, 'ms-fontColor-yellow', 'ms-fontColor-gray40') + ' ms-fontColor-green--hover'"
      }
    },
    {
      "elmType": "span",
      "style": {
        "padding-right": "4px",
        "display": "inline"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "YOUR FIELD NAME": "4"
        }
      },
      "attributes": {
        "iconName": "=if(Number(@currentField) >= 4, 'favoriteStarFill', 'favoriteStar')",
        "class": "=if(Number(@currentField) >= 4, 'ms-fontColor-yellow', 'ms-fontColor-gray40') + ' ms-fontColor-green--hover'"
      }
    },
    {
      "elmType": "span",
      "style": {
        "padding-right": "4px",
        "display": "inline"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "YOUR FIELD NAME": "5"
        }
      },
      "attributes": {
        "iconName": "=if(Number(@currentField) >= 5, 'favoriteStarFill', 'favoriteStar')",
        "class": "=if(Number(@currentField) >= 5, 'ms-fontColor-yellow', 'ms-fontColor-gray40') + ' ms-fontColor-green--hover'"
      }
    }	
  ]
}
copy to editor
  • Apply your template to your Choice Field.
  • Try adjusting colors and other style attributes.
  • Get other color references using the "live preview" linked below.

View / Edit Button

Display a simple view or edit button to open the SharePoint form.

Field:

  • Placeholder Field
Instructions
This template will produce this HTML structure:

1. Begin with column formatting schema:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div"
}
copy to editor

2. Add styling to the main div:

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "display": "flex",
    "justify-content": "center"
  }
}
copy to editor

3. Add a child button element with customRowAction, attributes and style properties.

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "display": "flex",
    "justify-content": "center"
  },
  "children": [
    {
      "elmType": "button",
      "customRowAction": {
        "action": "defaultClick"
      },
      "attributes": {
        "class": "ms-fontColor-white ms-fontColor-black--hover"
      },
      "style": {
        "border": "none",
        "cursor": "pointer",
        "background-color": "transparent"
      }
    }
  ]
}
copy to editor

4. Add a div inside the button with styling.

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "display": "flex",
    "justify-content": "center"
  },
  "children": [
    {
      "elmType": "button",
      "customRowAction": {
        "action": "defaultClick"
      },
      "attributes": {
        "class": "ms-fontColor-white ms-fontColor-black--hover"
      },
      "style": {
        "border": "none",
        "cursor": "pointer",
        "background-color": "transparent"
      },
      "children": [
        {
          "elmType": "div",
          "attributes": {
            "class": "ms-bgColor-blue ms-bgColor-blueLight--hover ms-fontColor-white ms-fontColor-black--hover"
          },
          "style": {
            "font-size": "12px",
            "font-family": "arial",
            "border": "1px solid Black",
            "border-radius": "7px",
            "padding": "3px 5px 3px 5px",
            "box-shadow": "2px 2px 2px #999"
          }
        }
      ]		
    }
  ]
}
copy to editor

5. Add two more divs inside the button div for the icon and label.

show code
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "display": "flex",
    "justify-content": "center"
  },
  "children": [
    {
      "elmType": "button",
      "customRowAction": {
        "action": "defaultClick"
      },
      "attributes": {
        "class": "ms-fontColor-white ms-fontColor-black--hover"
      },
      "style": {
        "border": "none",
        "cursor": "pointer",
        "background-color": "transparent"
      },
      "children": [
        {
          "elmType": "div",
          "attributes": {
            "class": "ms-bgColor-blue ms-bgColor-blueLight--hover ms-fontColor-white ms-fontColor-black--hover"
          },
          "style": {
            "font-size": "12px",
            "font-family": "arial",
            "border": "1px solid Black",
            "border-radius": "7px",
            "padding": "3px 5px 3px 5px",
            "box-shadow": "2px 2px 2px #999"
          },
          "children": [
            {
              "elmType": "div",
              "attributes": {
                "iconName": "Search"
              },
              "style": {
                "display": "inline-block",
                "vertical-align": "middle",
                "padding-right": "5px"
              }
            },
            {
              "elmType": "div",
              "txtContent": " VIEW",
              "style": {
                "display": "inline-block",
                "font-family": "arial",
                "vertical-align": "middle"
              }
            }
          ]
        }
      ]
    }
  ]
}
copy to editor
  • Apply your template to your Placeholder Field.
  • Try adjusting colors and other style attributes.
  • Get other color references using the "live preview" linked below.

JSON CODE EDITOR
copy
clear