Skip to content

Theming

Theming covers two things: switching between light and dark, and making a brand theme of your own. Use this page for both.

Republic follows the reader’s system setting. To force a theme, set data-theme on any element. It applies to everything inside, so a dark panel can sit on a light page.

<html data-theme="light">
…
<section data-theme="dark">A dark panel on a light page</section>
</html>

You do not write any dark styles yourself. Every colour, material and shadow token has a light and a dark value, and the theme picks one.

Republic has three tiers of tokens:

  • Primitives are raw values: the green ramp, spacing steps, font sizes.
  • Semantic tokens are roles: --rp-color-surface-raised, --rp-color-accent-default, --rp-font-family-ui, --rp-radius-card, the material gradients.
  • Component tokens are fixed sizes a component needs, such as the sidebar width.

A theme overrides the semantic tier only. That tier holds everything that makes Republic look like Republic: colours, font families, radii and materials. Spacing, type sizes and density stay as they are, so layouts do not break.

To make a theme:

  1. Pick a selector, such as [data-theme-brand]. Put it on <html> to theme the whole site, or on the same element as data-theme to theme one panel. A theme can only read light or dark from the element it is on, not from an ancestor, so a panel that sits inside another theme needs both attributes.
  2. Override the --rp-color-*, --rp-material-*, --rp-font-family-* and --rp-radius-* tokens you want to change.
  3. Give every colour a dark value too.
  4. Check contrast: text 4.5:1 and controls 3:1 against every surface they sit on, in both themes.
  5. Load your theme after Republic’s CSS.

Do not override primitives such as --rp-color-green-600. Semantic tokens are resolved when the CSS is built, so changing a primitive changes nothing on the page.

The example theme below swaps the green accent for blue, uses system fonts and tightens the radii. It is in the repository at apps/docs/src/themes/example.css. In each theme, the first card is Republic and the second is the same markup with data-theme-example added. Each card carries both attributes, as step 1 says:

<section data-theme="dark" data-theme-example>…</section>
Republic, light

Department of Records

Your request was sent on 3 March. We reply within five working days.

Example theme, light

Department of Records

Your request was sent on 3 March. We reply within five working days.

Republic, dark

Department of Records

Your request was sent on 3 March. We reply within five working days.

Example theme, dark

Department of Records

Your request was sent on 3 March. We reply within five working days.

apps/docs/src/themes/example.css
/* SPDX-FileCopyrightText: 2026 Global Icons Agency */
/* SPDX-License-Identifier: Apache-2.0 */
/*
Example theme: proof that a brand can restyle Republic by overriding the semantic tier only.
A blue accent, system fonts (nothing to download) and tighter radii. Spacing, sizes and
density stay as they are. Every colour pair here passes the same contrast rules as Republic.
Where to put data-theme-example:
- on :root (<html>), to theme the whole page. It follows the system setting, or the
data-theme on <html>;
- or on the same element as data-theme="light" or data-theme="dark", to theme one island.
Light or dark is read from the element the attribute is on, never from an ancestor, because
CSS cannot find the nearest themed ancestor. Inside a nested data-theme island that does not
carry the attribute too, Republic's own values for that theme apply.
*/
/* Light: the default, and data-theme="light" on the same element. */
[data-theme-example],
[data-theme-example][data-theme="light"] {
--rp-color-accent-default: #1e40af;
--rp-color-accent-text: #1d4ed8;
--rp-material-primary-background: linear-gradient(180deg, #2563eb 0%, #1d4ed8 55%, #1e3a8a 100%);
--rp-material-primary-edge: #172554;
--rp-material-primary-text: #ffffff;
--rp-font-family-display: Georgia, "Times New Roman", serif;
--rp-font-family-ui: system-ui, -apple-system, "Segoe UI", sans-serif;
--rp-radius-control: 4px;
--rp-radius-pill: 999px;
--rp-radius-card: 6px;
--rp-radius-plate: 8px;
--rp-radius-canvas: 8px;
}
/* Dark on the root, when the system asks for it and the root does not force light. */
@media (prefers-color-scheme: dark) {
:root[data-theme-example]:not([data-theme="light"]) {
--rp-color-accent-default: #60a5fa;
--rp-color-accent-text: #93c5fd;
--rp-material-primary-background: linear-gradient(
180deg,
#93c5fd 0%,
#60a5fa 55%,
#3b82f6 100%
);
--rp-material-primary-edge: #1d4ed8;
--rp-material-primary-text: #06122b;
}
}
/* Dark, set on the same element. */
[data-theme-example][data-theme="dark"] {
--rp-color-accent-default: #60a5fa;
--rp-color-accent-text: #93c5fd;
--rp-material-primary-background: linear-gradient(180deg, #93c5fd 0%, #60a5fa 55%, #3b82f6 100%);
--rp-material-primary-edge: #1d4ed8;
--rp-material-primary-text: #06122b;
}