Forum Discussion

JohnBloggs950's avatar
JohnBloggs950
Copper Contributor
Aug 22, 2023
Solved

How to add custom hex color to SharePoint list choice pills?

I'm afraid I'm too bad at coding. I've tried to go through all the materials but seem to not be able to land on a solution. Basically just need to assign custom hex colors to each of the choice optio...
  • Rob_Elliott's avatar
    Rob_Elliott
    Aug 22, 2023

    JohnBloggs950 you can simplify the JSON consderably by using the following instead, adjusting it as necessary. It's also easier to read & debug.

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
      "elmType": "div",
      "txtContent": "@currentField",
      "style": {
        "color": "=if(@currentField == 'Sales', '#ff0000', if(@currentField == 'Marketing', '#006aff', if(@currentField == 'Warehouse', '#b882d7','green')))",
        "background-color": "#f8f8f8",
        "border": "1px solid",
        "box-sizing": "border-box",
        "padding": "4px 8px 5px",
        "border-radius": "16px",
        "margin": "4px"
      }
    }

     The result is:

     

    Rob
    Los Gallardos
    Microsoft Power Automate Community Super User.
    Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)
     

Resources