DocumentationTheming

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.

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:

ValueResult
'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.
html
<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:

js
grid.setAttribute('theme', 'dark');   // the latest write wins
grid.options = { theme: 'light' };

To follow your own site toggle, set the option from your handler:

js
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:

css
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 #

TokenDefaultControls
--mb-fontinheritFont family. The grid uses your page font.
--mb-font-size0.9375remBody text size.
--mb-font-size-sm0.8125remSmall text, such as meta lines and filters.
--mb-font-size-xs0.6875remThe smallest text, such as counts and badges.
--mb-title-size1.0625remItem titles.
--mb-title-weight600Item title weight.
--mb-line1.5Line height.
--mb-label-transformnoneText transform of labels (.mb-cats, .mb-filters-label, .mb-badge).
--mb-label-tracking0Letter spacing of those labels.
--mb-cats-sepmiddle dotThe 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:

css
media-boxes {
  --mb-label-transform: uppercase;
  --mb-label-tracking: 0.08em;
}

Colour #

TokenLight defaultDark defaultControls
--mb-text#16181d#f2f4f7Main text.
--mb-text-muted#667085#98a2b3Secondary text.
--mb-surface#ffffff#1a1d23Card and control background.
--mb-surface-2#f4f5f7#23272fHover fills and quiet panels.
--mb-borderrgb(16 24 40 / 0.1)rgb(255 255 255 / 0.1)Hairlines.
--mb-accent#16181d#f2f4f7The active filter, the main button and highlights.
--mb-accent-contrast#ffffff#16181dText on the accent colour.
--mb-placeholder#e9ebef#262a32The box shown while an image loads.
--mb-focus#2f6fed#7aa7ffThe 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.

TokenDefaultControls
--mb-overlay-bgrgb(12 14 18 / 0.56)The hover overlay tint.
--mb-overlay-gradienta dark gradient to the bottomThe caption backdrop in the overlay skin.
--mb-overlay-text#ffffffText over images.
--mb-overlay-text-mutedrgb(255 255 255 / 0.76)Secondary text over images.
--mb-overlay-text-shadow0 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-size56pxThe play icon on video items.
--mb-play-bgrgb(255 255 255 / 0.92)Play icon background.
--mb-play-color#16181dPlay icon colour.
--mb-duration-bgrgb(8 10 14 / 0.72)The duration chip background.
--mb-duration-color#ffffffThe duration chip text. Also used by the gallery count chip and the stop button of an inline video.
--mb-player-bg#000000Background behind an inline video player (the bars around a video that does not fill the box).

Shape and space #

TokenDefaultControls
--mb-radius14pxCards and images.
--mb-radius-sm8pxSmall controls and inputs.
--mb-radius-pill999pxFilter pills and chips.
--mb-shadowa soft two-layer shadowCards at rest.
--mb-shadow-hovera deeper shadowCards on hover.
--mb-space-1 to --mb-space-64px to 32pxThe spacing scale (4, 8, 12, 16, 24, 32).
--mb-content-pad16pxPadding inside the content block.
--mb-control-h40pxHeight 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 #

TokenDefaultControls
--mb-easecubic-bezier(0.22, 0.8, 0.24, 1)The main easing curve.
--mb-ease-in-outcubic-bezier(0.65, 0, 0.35, 1)A symmetric curve.
--mb-duration450msLayout and filter moves.
--mb-duration-hover280msHover effects.
--mb-duration-fast160msSmall state changes.
--mb-stagger40msDelay between items that enter together.
TokenDefaultControls
--mb-lb-bgrgb(10 11 14 / 0.97)The backdrop.
--mb-lb-text#f5f6f8Lightbox text and icons.
--mb-lb-text-mutedrgb(245 246 248 / 0.66)Counter and captions.
--mb-lb-controlrgb(255 255 255 / 0.1)Button background.
--mb-lb-control-hoverrgb(255 255 255 / 0.2)Button hover background.
--mb-lb-thumb64pxSize 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:

css
.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:

PartClass
The element and the gridmedia-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:

css
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:

css
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:

html
<section style="background:#0f1114;padding:32px">
  <media-boxes theme="dark" skin="plain" columns="4"> ... </media-boxes>
</section>

Larger text and roomier captions:

css
media-boxes {
  --mb-font-size: 1rem;
  --mb-title-size: 1.25rem;
  --mb-content-pad: 20px;
}