Forum Discussion

bryanfrumkin220's avatar
bryanfrumkin220
Copper Contributor
Aug 18, 2025

SharePoint Form Conditional Formatting

Hello Community!


I am working to have an image display in my sharepoint header if it isn't null

Currently it is displaying the image great, I have the image stored in a column titled 'Headshot' that's an Image column, but I want to only show the image and frame if the value isn't null for this column.

Any help would be great!

 

Visual of Current Header:

 

 

 

 

 

 

Current Header Code:

 

 

1 Reply

  • PankajBadoni's avatar
    PankajBadoni
    Iron Contributor

    I think this is a duplicate issue: 
    https://techcommunity.microsoft.com/discussions/sharepoint_general/sharepoint-form-header-conditional-formatting/4445234

    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"
                        }
                    }
                ]
            }
        ]
    }

Resources