Back to column formats
Column formattingSharePoint 2019SharePoint Online

Yes/No Checkbox

This sample uses Fluent UI icons and theme classes to provide a better visualization for Yes/No fields while respecting theme colors.

Yes/No Checkbox 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",
  "children": [
    {
      "elmType": "div",
      "attributes": {
        "iconName": "=if(@currentField,'CheckboxComposite','Checkbox')",
        "class": "=if(@currentField,'ms-fontColor-neutralPrimary','ms-fontColor-neutralTertiary')+' ms-fontSize-l'"
      },
      "style": {
        "cursor": "pointer"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "YesNoColumnInternalName": "=if(@currentField , '0' , '1' )"
        }
      }
    }
  ]
}

From the contributor

How to use this sample

Summary

This sample uses Office UI Fabric icons and theme classes to provide a better visualization for Yes/No fields while respecting theme colors.

The icons and theme colors are conditionally applied based on the field's value. By using the ms-fontColor classes, the icon works well in both light and dark themes (as well as custom themes). In addition, regardless of value, the ms-fontSize-l class is applied to make the icon large enough to stand on its own.

Value Class Icon
Yes ms-fontColor-neutralPrimary CheckboxComposite
No ms-fontColor-neutralTertiary Checkbox

screenshot of the sample

Also, this sample uses the setValue of customRowAction to update the field. You need to set the actionInput to the internal name of the column to be updated.

screenshot of the sample

View requirements

  • This format can be applied to a Yes/No column

Sample

Solution Author(s)
yesno-checkbox.json Chris Kent, Tetsuya Kawahara

Version history

Version Date Comments
1.0 August 18, 2018 Initial release
1.1 November 21, 2021 Modified to update item using setValue
1.2 October 29, 2023 Changed CSS class so that a checkbox also appears in SharePoint Server 2019

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.


Additional notes

An additional version using Abstract Tree Syntax (AST) is also provided for environments where the Excel-style expressions are not supported.