# Theming and dark mode

> Switch theme and brand with the data-theme and data-brand attributes, on the page or on a single element.

Aloxe themes with two attributes:

- `data-theme` is `light` or `dark`.
- `data-brand` is the brand ramp, `cobalt` in the free package.

## On the whole page

Set both on the root element.

```html
<html data-theme="dark" data-brand="cobalt">
```

If `data-theme` is missing, the page follows the operating system through `prefers-color-scheme`. Setting `data-theme="light"` forces light.

## On one element

Both attributes work on any element, not only `html`. Use this for a preview, an embedded widget or a section with its own theme.

```html
<section data-theme="dark" data-brand="cobalt">
  <!-- everything inside uses the dark theme -->
</section>
```

## Set both attributes

For scoped theming, put `data-theme` and `data-brand` on the same element. The semantic tokens, such as `--aloxe-accent-default`, are resolved where the theme rule applies. If you set only `data-brand` on an inner element, the semantic tokens keep the value resolved by the ancestor, and the brand change does not reach them. Setting both makes the element resolve the tokens again with its own theme and brand.

## Dark mode

Dark mode changes colour and elevation tokens only. Type, spacing, radius and motion stay the same. To let users choose, store their choice and write it to `data-theme`; a library such as `next-themes` with `attribute="data-theme"` does this.

## Brands

The free `@aloxe/tokens` package contains Cobalt. Ember and Moss are a Pro download. A brand only replaces the `brand/50` to `brand/950` ramp, so the same components work with every brand.

## Check your setup

If colours do not change when you set an attribute, check that both attributes are on the same element and that the CSS from `@aloxe/tokens/aloxe.css` is loaded.
