Forum Discussion

bryanfrumkin220's avatar
bryanfrumkin220
Copper Contributor
Aug 18, 2025

SharePoint Form (Header) Conditional Formatting

Hello Community!

I am working to make an image column only display if it is not Null. The header is currently displaying fine, but I only need the image frame to be present if the headshot is null

The column is $Headshot

Any help would be very much appreciated

Current Header:

 

 

 

 

Current Header JSON:
{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "div",
    "style": {
        "display": "flex",
        "align-items": "center",
        "background-color": "=if([$IsDarkTheme], '#1f1f1f', '#f3f2f1')",
        "padding": "20px",
        "border-radius": "12px",
        "box-shadow": "0 4px 12px rgba(0, 0, 0, 0.15)",
        "width": "100%",
        "margin-bottom": "20px",
        "border": "2px solid #e1dfdd"
    },
    "children": [
        {
            "elmType": "img",
            "style": {
                "width": "80px",
                "height": "80px",
                "border-radius": "50%",
                "object-fit": "cover",
                "margin-right": "20px",
                "border": "2px solid #ccc"
            },
            "attributes": {
                "src": "=''+[$Headshot.serverRelativeUrl]"
            }
        },
        {
            "elmType": "div",
            "style": {
                "text-align": "left"
            },
            "children": [
                {
                    "elmType": "div",
                    "style": {
                        "font-size": "26px",
                        "font-weight": "600",
                        "color": "=if([$IsDarkTheme], '#ffffff', '#323130')",
                        "margin-bottom": "6px"
                    },
                    "txtContent": "= 'Employee Overview for ' + [$Nickname]"
                },
                {
                    "elmType": "div",
                    "style": {
                        "font-size": "14px",
                        "color": "=if([$IsDarkTheme], '#cccccc', '#605e5c')"
                    },
                    "txtContent": ""
                }
            ]
        }
    ]
}


{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "div",
    "style": {
        "display": "flex",
        "align-items": "center",
        "background-color": "=if([$IsDarkTheme], '#1f1f1f', '#f3f2f1')",
        "padding": "20px",
        "border-radius": "12px",
        "box-shadow": "0 4px 12px rgba(0, 0, 0, 0.15)",
        "width": "100%",
        "margin-bottom": "20px",
        "border": "2px solid #e1dfdd"
    },
    "children": [
        {
            "elmType": "img",
            "style": {
                "width": "80px",
                "height": "80px",
                "border-radius": "50%",
                "object-fit": "cover",
                "margin-right": "20px",
                "border": "2px solid #ccc"
            },
            "attributes": {
                "src": "=''+[$Headshot.serverRelativeUrl]"
            }
        },
        {
            "elmType": "div",
            "style": {
                "text-align": "left"
            },
            "children": [
                {
                    "elmType": "div",
                    "style": {
                        "font-size": "26px",
                        "font-weight": "600",
                        "color": "=if([$IsDarkTheme], '#ffffff', '#323130')",
                        "margin-bottom": "6px"
                    },
                    "txtContent": "= 'Employee Overview for ' + [$Nickname]"
                },
                {
                    "elmType": "div",
                    "style": {
                        "font-size": "14px",
                        "color": "=if([$IsDarkTheme], '#cccccc', '#605e5c')"
                    },
                    "txtContent": ""
                }
            ]
        }
    ]
}

3 Replies

  • PankajBadoni's avatar
    PankajBadoni
    Iron Contributor

    Try this, working at my end:
    Also, instead of column formatting, use header formatting.

    {
        "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/header-formatting.schema.json",
        "elmType": "div",
        "style": {
            "display": "flex",
            "align-items": "center",
            "padding": "20px",
            "border-radius": "12px",
            "background-color": "#f3f2f1",
            "border": "1px solid #ccc"
        },
        "children": [
            {
                "elmType": "div",
                "style": {
                    "margin-right": "20px"
                },
                "children": [
                    {
                        "elmType": "img",
                        "attributes": {
                            "src": "=if([$Headshot.serverRelativeUrl] != '', [$Headshot.serverRelativeUrl], '')"
                        },
                        "style": {
                            "width": "80px",
                            "height": "80px",
                            "border-radius": "50%",
                            "object-fit": "cover",
                            "border": "2px solid #ccc",
                            "display": "=if([$Headshot.serverRelativeUrl] != '', 'block', 'none')"
                        }
                    }
                ]
            },
            {
                "elmType": "div",
                "children": [
                    {
                        "elmType": "div",
                        "txtContent": "= 'Employee Overview for ' + [$Nickname]",
                        "style": {
                            "font-size": "20px",
                            "font-weight": "bold"
                        }
                    }
                ]
            }
        ]
    }

  • pradejain's avatar
    pradejain
    Iron Contributor

    bryanfrumkin220​ Please mark as resolved if this fixes your issue.

    In SharePoint column formatting JSON, you can wrap your img element with a conditional "display" style or use the ="if()" expression.

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
      "elmType": "div",
      "style": {
        "display": "flex",
        "align-items": "center",
        "background-color": "=if([$IsDarkTheme], '#1f1f1f', '#f3f2f1')",
        "padding": "20px",
        "border-radius": "12px",
        "box-shadow": "0 4px 12px rgba(0, 0, 0, 0.15)",
        "width": "100%",
        "margin-bottom": "20px",
        "border": "2px solid #e1dfdd"
      },
      "children": [
        {
          "elmType": "img",
          "style": {
            "width": "80px",
            "height": "80px",
            "border-radius": "50%",
            "object-fit": "cover",
            "margin-right": "20px",
            "border": "2px solid #ccc",
            "display": "=if([$Headshot] == '', 'none', 'block')"   // <-- Hide if null
          },
          "attributes": {
            "src": "=''+[$Headshot.serverRelativeUrl]"
          }
        },
        {
          "elmType": "div",
          "style": {
            "text-align": "left"
          },
          "children": [
            {
              "elmType": "div",
              "style": {
                "font-size": "26px",
                "font-weight": "600",
                "color": "=if([$IsDarkTheme], '#ffffff', '#323130')",
                "margin-bottom": "6px"
              },
              "txtContent": "= 'Employee Overview for ' + [$Nickname]"
            },
            {
              "elmType": "div",
              "style": {
                "font-size": "14px",
                "color": "=if([$IsDarkTheme], '#cccccc', '#605e5c')"
              },
              "txtContent": ""
            }
          ]
        }
      ]
    }

Resources