Styling the banner with CSS
The banner designer in the dashboard sets the template, the position, the
colors, the logo and the text. When you need more, such as a banner that
follows the site's dark mode or pill-shaped buttons, set the --cl-* CSS
variables in the site's own stylesheet.
The banner renders in a closed Shadow DOM, so the site's CSS cannot reach its elements. CSS variables are the exception: they inherit into the banner. The variables on this page are the whole styling API.
Where to set the variables
Set them on the four elements the banner adds to the page:
[data-consentlayer],
[data-consentlayer-prefs],
[data-consentlayer-floating],
[data-consentlayer-toast] {
--cl-bg: #ffffff;
--cl-fg: #111111;
}| Element | What it holds |
|---|---|
[data-consentlayer] | The banner |
[data-consentlayer-prefs] | The preferences panel |
[data-consentlayer-floating] | The button that opens the preferences again |
[data-consentlayer-toast] | The Global Privacy Control notice |
Set the variables on these elements, not on :root or body. The banner
sets its defaults on its own elements, so a value set higher in the page does
not replace them.
Every variable is optional. When you do not set a variable, the banner uses the dashboard setting or its built-in default, so it looks as it did before.
Colors
| Variable | Controls | Default |
|---|---|---|
--cl-bg | Background of the banner, the panel and the reopen button | Dashboard background color |
--cl-fg | Headings, labels and the close button on hover | Dashboard text color |
--cl-muted | Body text, descriptions and links | A mix of text and background |
--cl-border | Borders, dividers and the off state of the toggles | A mix of text and background |
--cl-accent | The on state of the toggles | Dashboard Accept button color |
--cl-primary | Focus outlines and the GPC checkbox | Dashboard brand color |
--cl-close-hover-bg | Background of the close button on hover | A mix of text and background |
Buttons
| Variable | Controls | Default |
|---|---|---|
--cl-accept-bg | Accept button background | Dashboard Accept button color |
--cl-accept-fg | Accept button text | Dark or white, picked for contrast |
--cl-reject-bg | Reject button background | Dashboard Reject button color |
--cl-reject-fg | Reject button text | Dark or white, picked for contrast |
--cl-save-bg | Save preferences button background | Same as --cl-accept-bg |
--cl-save-fg | Save preferences button text | Same as --cl-accept-fg |
--cl-accept-bg-hover | Accept button background on hover | Same as --cl-accept-bg |
--cl-reject-bg-hover | Reject button background on hover | Same as --cl-reject-bg |
--cl-save-bg-hover | Save preferences button background on hover | Same as --cl-save-bg |
--cl-button-hover-opacity | Opacity of the buttons on hover | 0.9 |
When you set a hover color, also set --cl-button-hover-opacity: 1. If you do
not, the hover color shows at 90% opacity.
--cl-accent-fg still works and sets the Accept button text, but use
--cl-accept-fg in new CSS.
Shape and shadows
| Variable | Controls | Default |
|---|---|---|
--cl-radius | Corner radius of panels and buttons together | 8px |
--cl-panel-radius | Corner radius of the banner and the preferences panel | --cl-radius |
--cl-button-radius | Corner radius of the Accept, Reject and Save buttons | --cl-radius |
--cl-shadow | Shadow of the banner and the preferences panel | A soft shadow for light pages |
--cl-shadow-floating | Shadow of the reopen button and the GPC notice | A soft shadow for light pages |
--cl-shadow-floating-hover | Shadow of the reopen button on hover | --cl-shadow-floating if set, else a soft shadow |
--cl-backdrop | The color behind the modal template and the preferences panel | Dark navy at 48% |
Use --cl-shadow: none to turn the shadows off on dark pages. The wide bar
template has square corners and ignores the panel radius.
Fonts
| Variable | Controls | Default |
|---|---|---|
--cl-font | All banner text | The system font |
--cl-heading-font | The banner heading and the panel heading | --cl-font |
--cl-heading-weight | Weight of those headings | 700 (600 in the wide bar) |
The banner does not load fonts. Use a font that the site already loads.
Position
| Variable | Controls | Default |
|---|---|---|
--cl-offset-bottom | Extra space under bottom-positioned banners, the reopen button and the GPC notice. Use it when the site has its own fixed bar at the bottom of the screen. | 0px |
Follow the site's light and dark themes
Set the light values first, then the dark values under the selector the site uses for dark mode. This example follows the visitor's system setting:
[data-consentlayer],
[data-consentlayer-prefs],
[data-consentlayer-floating],
[data-consentlayer-toast] {
--cl-bg: #ffffff;
--cl-fg: #111111;
--cl-border: #e5e5e5;
--cl-accept-bg: #111111;
--cl-accept-fg: #ffffff;
--cl-accept-bg-hover: #333333;
--cl-button-hover-opacity: 1;
--cl-panel-radius: 12px;
--cl-button-radius: 999px;
}
@media (prefers-color-scheme: dark) {
[data-consentlayer],
[data-consentlayer-prefs],
[data-consentlayer-floating],
[data-consentlayer-toast] {
--cl-bg: #16181d;
--cl-fg: #f2f2f0;
--cl-border: #2c2f36;
--cl-accept-bg: #f2f2f0;
--cl-accept-fg: #111111;
--cl-accept-bg-hover: #d9d9d6;
--cl-reject-bg: transparent;
--cl-reject-fg: #f2f2f0;
--cl-shadow: none;
--cl-backdrop: rgba(0, 0, 0, 0.7);
}
}When the site has a theme switch that sets an attribute or a class, use that
selector in place of the media query, for example
[data-theme="dark"] [data-consentlayer]. A site builder's color tokens work
too: --cl-bg: var(--wp--preset--color--background); follows the theme
when the token changes.
When you set --cl-accept-bg, also set --cl-accept-fg. The banner picks
the text color for contrast only for the dashboard color, not for a color you
set in CSS. The same applies to Reject and Save.