Theming (legacy)

Stacks provides a robust theming API to handle theming in various contexts.

You are viewing a deprecated version of our theming. View the current theming information here.

Like light and dark modes, Stacks has baked-in theming available as primary and secondary CSS color variables. These can be overridden in various scopes. By default, the Stacks primary and secondary variables are Stack Overflow’s branded orange and blue, respectively, at a global scope, affecting every element on the page. These can be overridden in the context of your product, e.g. Teams, a Collective, or Stack Exchange Site. Both primary and secondary colors are available in the full spectrum of atomic classes and variables.

At its core, our theming is powered by CSS variables that are split into primary and secondary H, S, L, and R, G, B values. For example:

--theme-base-primary-color-legacy-h: 313;
--theme-base-primary-color-legacy-s: 76%;
--theme-base-primary-color-legacy-l: 54%;
--theme-base-primary-color-legacy-r: 227;
--theme-base-primary-color-legacy-g: 49;
--theme-base-primary-color-legacy-b: 188;

--theme-base-secondary-color-legacy-h: 313;
--theme-base-secondary-color-legacy-s: 76%;
--theme-base-secondary-color-legacy-l: 54%;
--theme-base-secondary-color-legacy-r: 227;
--theme-base-secondary-color-legacy-g: 49;
--theme-base-secondary-color-legacy-b: 188;

These then get combined to generate the full set of color stops. Overriding them is as simple as redefining those individual theming variables.

By default, we take those single primary and secondary colors and generate an appropriate dark mode equivalent. However, what if your branding color is dark purple—or black? You can pass an optional dark mode override:

--theme-dark-primary-color-legacy-h: 288;
--theme-dark-primary-color-legacy-s: 45%;
--theme-dark-primary-color-legacy-l: 60%;
--theme-dark-primary-color-legacy-r: 180;
--theme-dark-primary-color-legacy-g: 105;
--theme-dark-primary-color-legacy-b: 199;

--theme-dark-secondary-color-legacy-h: 313;
--theme-dark-secondary-color-legacy-s: 76%;
--theme-dark-secondary-color-legacy-l: 54%;
--theme-dark-secondary-color-legacy-r: 227;
--theme-dark-secondary-color-legacy-g: 49;
--theme-dark-secondary-color-legacy-b: 188;

Stacks allows for further theming various portions of a page. You can simply pair the .themed class with an atomic color stop, and a new theming scope. For this example, we’re using a class name of .theme-team-[xxx] with a unique ID appended.

<div class="bg-theme-primary-legacy-500"></div>
<div class="themed theme-team-001 bg-theme-primary-legacy-400"></div>
<div class="themed theme-team-002 bg-theme-primary-legacy-400"></div>
<div class="themed theme-team-003 bg-theme-primary-legacy-400"></div>
<style>
.theme-team-001 {
--theme-base-primary-color-legacy-h: 349;
--theme-base-primary-color-legacy-s: 81%;
--theme-base-primary-color-legacy-l: 58%;
--theme-base-primary-color-legacy-r: 235;
--theme-base-primary-color-legacy-g: 59;
--theme-base-primary-color-legacy-b: 90;

--theme-base-secondary-color-legacy-h: 349;
--theme-base-secondary-color-legacy-s: 81%;
--theme-base-secondary-color-legacy-l: 58%;
--theme-base-secondary-color-legacy-r: 235;
--theme-base-secondary-color-legacy-g: 59;
--theme-base-secondary-color-legacy-b: 90;
}

.theme-team-002 {
--theme-base-primary-color-legacy-h: 41;
--theme-base-primary-color-legacy-s: 93%;
--theme-base-primary-color-legacy-l: 58%;
--theme-base-primary-color-legacy-r: 247;
--theme-base-primary-color-legacy-g: 183;
--theme-base-primary-color-legacy-b: 49;

--theme-base-secondary-color-legacy-h: 41;
--theme-base-secondary-color-legacy-s: 93%;
--theme-base-secondary-color-legacy-l: 58%;
--theme-base-secondary-color-legacy-r: 247;
--theme-base-secondary-color-legacy-g: 183;
--theme-base-secondary-color-legacy-b: 49;
}

.theme-team-003 {
--theme-base-primary-color-legacy-h: 288;
--theme-base-primary-color-legacy-s: 76%;
--theme-base-primary-color-legacy-l: 38%;
--theme-base-primary-color-legacy-r: 141;
--theme-base-primary-color-legacy-g: 23;
--theme-base-primary-color-legacy-b: 170;

--theme-base-secondary-color-legacy-h: 288;
--theme-base-secondary-color-legacy-s: 76%;
--theme-base-secondary-color-legacy-l: 38%;
--theme-base-secondary-color-legacy-r: 141;
--theme-base-secondary-color-legacy-g: 23;
--theme-base-secondary-color-legacy-b: 170;

/* Override colors for dark mode only */
--theme-dark-primary-color-legacy-h: 288;
--theme-dark-primary-color-legacy-s: 45%;
--theme-dark-primary-color-legacy-l: 60%;
--theme-dark-primary-color-legacy-r: 180;
--theme-dark-primary-color-legacy-g: 105;
--theme-dark-primary-color-legacy-b: 199;

--theme-dark-secondary-color-legacy-h: 288;
--theme-dark-secondary-color-legacy-s: 45%;
--theme-dark-secondary-color-legacy-l: 60%;
--theme-dark-secondary-color-legacy-r: 180;
--theme-dark-secondary-color-legacy-g: 105;
--theme-dark-secondary-color-legacy-b: 199;
}
</style>
body
1 2 Next
.themed.theme-team-001
C
1 2 Next
.themed.theme-team-002
E
1 2 Next
.themed.theme-team-003
F
1 2 Next
body .theme-light__forced
1 2 Next
.theme-light__forced .themed.theme-team-001
C
1 2 Next
.theme-light__forced .themed.theme-team-002
E
1 2 Next
.theme-light__forced .themed.theme-team-003
F
1 2 Next
body .theme-dark__forced
1 2 Next
.theme-dark__forced .themed.theme-team-001
C
1 2 Next
.theme-dark__forced .themed.theme-team-002
E
1 2 Next
.theme-dark__forced .themed.theme-team-003
F
1 2 Next
Deploys by Netlify