ConsentLayer
Guides

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;
}
ElementWhat 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

VariableControlsDefault
--cl-bgBackground of the banner, the panel and the reopen buttonDashboard background color
--cl-fgHeadings, labels and the close button on hoverDashboard text color
--cl-mutedBody text, descriptions and linksA mix of text and background
--cl-borderBorders, dividers and the off state of the togglesA mix of text and background
--cl-accentThe on state of the togglesDashboard Accept button color
--cl-primaryFocus outlines and the GPC checkboxDashboard brand color
--cl-close-hover-bgBackground of the close button on hoverA mix of text and background

Buttons

VariableControlsDefault
--cl-accept-bgAccept button backgroundDashboard Accept button color
--cl-accept-fgAccept button textDark or white, picked for contrast
--cl-reject-bgReject button backgroundDashboard Reject button color
--cl-reject-fgReject button textDark or white, picked for contrast
--cl-save-bgSave preferences button backgroundSame as --cl-accept-bg
--cl-save-fgSave preferences button textSame as --cl-accept-fg
--cl-accept-bg-hoverAccept button background on hoverSame as --cl-accept-bg
--cl-reject-bg-hoverReject button background on hoverSame as --cl-reject-bg
--cl-save-bg-hoverSave preferences button background on hoverSame as --cl-save-bg
--cl-button-hover-opacityOpacity of the buttons on hover0.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

VariableControlsDefault
--cl-radiusCorner radius of panels and buttons together8px
--cl-panel-radiusCorner radius of the banner and the preferences panel--cl-radius
--cl-button-radiusCorner radius of the Accept, Reject and Save buttons--cl-radius
--cl-shadowShadow of the banner and the preferences panelA soft shadow for light pages
--cl-shadow-floatingShadow of the reopen button and the GPC noticeA soft shadow for light pages
--cl-shadow-floating-hoverShadow of the reopen button on hover--cl-shadow-floating if set, else a soft shadow
--cl-backdropThe color behind the modal template and the preferences panelDark 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

VariableControlsDefault
--cl-fontAll banner textThe system font
--cl-heading-fontThe banner heading and the panel heading--cl-font
--cl-heading-weightWeight of those headings700 (600 in the wide bar)

The banner does not load fonts. Use a font that the site already loads.

Position

VariableControlsDefault
--cl-offset-bottomExtra 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.