Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Can Different Knowledge Blocks Be Applied Based on GUI Light or Dark Theme?

GeorgeO
Tera Contributor

Is it possible to apply a different knowledge block to an article depending on whether it is opened in light or dark theme?

I have lots of CSS styles contained in knowledge blocks, and unfortunately some have hard-coded text colors which don't work so well in dark theme.

 

Thanks

1 REPLY 1

MaryG
ServiceNow Employee

Hi @GeorgeO — there's no native way to conditionally swap Knowledge Blocks based on light/dark theme, but the better fix is likely upstream in how the CSS is written rather than swapping blocks.

The cleanest approach: replace hard-coded color values in your block CSS with CSS custom properties that respond to the user's theme automatically.

For example, instead of:
color: #1a1a1a;

Use:
color: var(--now-color--neutral-18, #1a1a1a);

Now UX ships a full set of CSS variables (--now-color--, --now-color-text--, etc.) that flip automatically between light and dark theme. If your blocks reference those instead of hex values, they adapt without any conditional logic.

If swapping blocks is still the direction you want to go, you could embed a small inline script in a block that checks document.documentElement and shows/hides content based on the active theme class — but that's fragile and not something ServiceNow supports officially.

Worth auditing the hard-coded values first — in most cases replacing 3-4 color declarations fixes the problem across all your blocks at once.

Note: CSS variable names have shifted across releases, so it's worth verifying the exact token names against the Now Design System docs for your release before updating your blocks. The pattern is consistent but specific variable names may differ.