Theming
Restyle Media Boxes with CSS custom properties. Switch between light, dark and auto themes, match your brand colours and restyle the lightbox with no code.
Media Boxes is styled with CSS custom properties (design tokens), all starting with --mb-. You change the look by overriding tokens in your own stylesheet, with no build step and no need to edit the plugin's CSS.
All engine CSS lives in one cascade layer, @layer media-boxes, and its selectors have the lowest specificity. Any ordinary rule in your own stylesheet therefore wins, whatever its specificity and whether it loads before or after media-boxes.css.
media-boxes {
--mb-accent: #e54e53;
--mb-accent-contrast: #ffffff;
--mb-radius: 6px;
--mb-focus: #e54e53;
}Light, dark and auto #
The theme option picks the colour set:
| Value | Result |
|---|---|
'light' (default) | The light tokens. |
'dark' | The dark tokens, whatever the visitor's system says. |
'auto' | Follows prefers-color-scheme: light by default, dark when the system is dark. |
<media-boxes theme="auto" columns="3"> ... </media-boxes>The engine sets data-theme on the element and the matching color-scheme. Change theme at any time, either way:
grid.setAttribute('theme', 'dark'); // the latest write wins
grid.options = { theme: 'light' };To follow your own site toggle, set the option from your handler:
document.querySelector('#theme-toggle').addEventListener('click', () => {
const next = document.documentElement.dataset.theme === 'dark' ? 'light' : 'dark';
document.documentElement.dataset.theme = next;
document.querySelectorAll('media-boxes').forEach((g) => { g.options = { theme: next }; });
});To change only the dark colours, target the attribute:
media-boxes[data-theme='dark'] {
--mb-surface: #14161a;
--mb-surface-2: #1c1f25;
}Token reference #
Set tokens on media-boxes to affect every grid, on #my-grid to affect one, or on :root for tokens that the grid inherits. The lightbox section explains why the lightbox needs its own rule.
Type #
| Token | Default | Controls |
|---|---|---|
--mb-font | inherit | Font family. The grid uses your page font. |
--mb-font-size | 0.9375rem | Body text size. |
--mb-font-size-sm | 0.8125rem | Small text, such as meta lines and filters. |
--mb-font-size-xs | 0.6875rem | The smallest text, such as counts and badges. |
--mb-title-size | 1.0625rem | Item titles. |
--mb-title-weight | 600 | Item title weight. |
--mb-line | 1.5 | Line height. |
--mb-label-transform | none | Text transform of labels (.mb-cats, .mb-filters-label, .mb-badge). |
--mb-label-tracking | 0 | Letter spacing of those labels. |
--mb-cats-sep | middle dot | The separator drawn between terms in .mb-cats. |
--mb-cats-group-sep | '/' | The separator between groups when showTerms is 'all'. |
Labels are in sentence case by default. To bring capitals back:
media-boxes {
--mb-label-transform: uppercase;
--mb-label-tracking: 0.08em;
}Colour #
| Token | Light default | Dark default | Controls |
|---|---|---|---|
--mb-text | #16181d | #f2f4f7 | Main text. |
--mb-text-muted | #667085 | #98a2b3 | Secondary text. |
--mb-surface | #ffffff | #1a1d23 | Card and control background. |
--mb-surface-2 | #f4f5f7 | #23272f | Hover fills and quiet panels. |
--mb-border | rgb(16 24 40 / 0.1) | rgb(255 255 255 / 0.1) | Hairlines. |
--mb-accent | #16181d | #f2f4f7 | The active filter, the main button and highlights. |
--mb-accent-contrast | #ffffff | #16181d | Text on the accent colour. |
--mb-placeholder | #e9ebef | #262a32 | The box shown while an image loads. |
--mb-focus | #2f6fed | #7aa7ff | The focus ring. Keep it visible against your backgrounds. |
Overlay and video badge #
The overlay sits on top of images, so it stays dark with light text in every theme.
| Token | Default | Controls |
|---|---|---|
--mb-overlay-bg | rgb(12 14 18 / 0.56) | The hover overlay tint. |
--mb-overlay-gradient | a dark gradient to the bottom | The caption backdrop in the overlay skin. |
--mb-overlay-text | #ffffff | Text over images. |
--mb-overlay-text-muted | rgb(255 255 255 / 0.76) | Secondary text over images. |
--mb-overlay-text-shadow | 0 1px 3px rgb(8 10 14 / 0.55), 0 0 10px rgb(8 10 14 / 0.35) | Soft shadow behind the category label over images, so it stays readable on very light photos. |
--mb-play-size | 56px | The play icon on video items. |
--mb-play-bg | rgb(255 255 255 / 0.92) | Play icon background. |
--mb-play-color | #16181d | Play icon colour. |
--mb-duration-bg | rgb(8 10 14 / 0.72) | The duration chip background. |
--mb-duration-color | #ffffff | The duration chip text. Also used by the gallery count chip and the stop button of an inline video. |
--mb-player-bg | #000000 | Background behind an inline video player (the bars around a video that does not fill the box). |
Shape and space #
| Token | Default | Controls |
|---|---|---|
--mb-radius | 14px | Cards and images. |
--mb-radius-sm | 8px | Small controls and inputs. |
--mb-radius-pill | 999px | Filter pills and chips. |
--mb-shadow | a soft two-layer shadow | Cards at rest. |
--mb-shadow-hover | a deeper shadow | Cards on hover. |
--mb-space-1 to --mb-space-6 | 4px to 32px | The spacing scale (4, 8, 12, 16, 24, 32). |
--mb-content-pad | 16px | Padding inside the content block. |
--mb-control-h | 40px | Height of buttons, pills and inputs. Keep it at 40px or more for touch. |
The tokens --mb-space-1, --mb-space-2, --mb-space-3, --mb-space-4, --mb-space-5 and --mb-space-6 are 4px, 8px, 12px, 16px, 24px and 32px.
Motion #
| Token | Default | Controls |
|---|---|---|
--mb-ease | cubic-bezier(0.22, 0.8, 0.24, 1) | The main easing curve. |
--mb-ease-in-out | cubic-bezier(0.65, 0, 0.35, 1) | A symmetric curve. |
--mb-duration | 450ms | Layout and filter moves. |
--mb-duration-hover | 280ms | Hover effects. |
--mb-duration-fast | 160ms | Small state changes. |
--mb-stagger | 40ms | Delay between items that enter together. |
Lightbox #
| Token | Default | Controls |
|---|---|---|
--mb-lb-bg | rgb(10 11 14 / 0.97) | The backdrop. |
--mb-lb-text | #f5f6f8 | Lightbox text and icons. |
--mb-lb-text-muted | rgb(245 246 248 / 0.66) | Counter and captions. |
--mb-lb-control | rgb(255 255 255 / 0.1) | Button background. |
--mb-lb-control-hover | rgb(255 255 255 / 0.2) | Button hover background. |
--mb-lb-thumb | 64px | Size of the thumbnail strip images. |
Styling the lightbox #
The lightbox is one <dialog class="mb-lightbox"> that lives in <body>, so tokens set on media-boxes do not reach it. Set them on .mb-lightbox:
.mb-lightbox {
--mb-lb-bg: rgb(20 8 10 / 0.97);
--mb-focus: #ff7a7d;
--mb-radius: 6px;
}It is always dark, whatever the theme of the grid.
Overriding classes #
Every class is prefixed mb- and every state is is-*. These are the ones you will most often style:
| Part | Class |
|---|---|
| The element and the grid | media-boxes, .mb-grid |
| An item, its image, its text | .mb-item, .mb-media, .mb-content |
| Text parts | .mb-cats, .mb-title, .mb-text, .mb-meta, .mb-price, .mb-author, .mb-date, .mb-badge |
| Hover | .mb-overlay, .mb-overlay-icon, .mb-overlay-label |
| Video | .mb-play, .mb-duration, .mb-player, .mb-player-close |
| Item gallery | .mb-gallery, .mb-gallery-count |
| Toolbar | .mb-toolbar, .mb-filters, .mb-filter, .mb-search, .mb-sort, .mb-select, .mb-count |
| Footer | .mb-footer, .mb-load-more, .mb-pages, .mb-page, .mb-empty |
| States | .is-active, .is-hidden, .is-entering, .is-leaving, .is-loaded, .is-loading |
| Lightbox | .mb-lightbox, .mb-lb-btn, .mb-lb-topbar, .mb-lb-caption, .mb-lb-thumbs |
The element sets data-skin, data-layout, data-theme, data-enter, data-hover-overlay and data-hover-image on itself, so you can scope a rule to one skin or layout:
media-boxes[data-skin='card'] .mb-title { font-size: 1.125rem; }
media-boxes .mb-filters:not([data-ui='tabs']) .mb-filter:is(.is-active, [aria-pressed='true']) {
background: #e54e53;
color: #fff;
}Examples #
A brand-coloured grid with sharper corners:
media-boxes {
--mb-accent: #e54e53;
--mb-accent-contrast: #ffffff;
--mb-radius: 4px;
--mb-radius-sm: 4px;
--mb-shadow: none;
--mb-shadow-hover: 0 8px 24px rgb(0 0 0 / 0.14);
}A grid inside a dark section that does not change with the visitor's system:
<section style="background:#0f1114;padding:32px">
<media-boxes theme="dark" skin="plain" columns="4"> ... </media-boxes>
</section>Larger text and roomier captions:
media-boxes {
--mb-font-size: 1rem;
--mb-title-size: 1.25rem;
--mb-content-pad: 20px;
}