Forum Discussion
SharePoint Form (Header) Conditional Formatting
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": ""
}
]
}
]
}
- bryanfrumkin220Aug 20, 2025Copper Contributor
Thank you