Theme
Theme sets light or dark mode, spacing, corners, shadows and material for everything inside it.
A Theme holds the settings that every component inside it uses. There are eight: appearance, density, radius, contrast, pointer, depth, material and size. Put one Theme at the root of your app, and set only the values you want to change, because the defaults suit most apps.
The defaults are appearance="light", density="default", radius="full", contrast="normal", pointer="auto", depth="elevated", material="solid" and size="2". pointer="auto" follows the device, so a touch screen gets larger controls and slightly larger reading text.
Themes nest. A Theme inside another changes only the settings you give it and keeps the rest from the theme around it. Use a nested Theme for a dark panel on a light page, or for a compact table inside an app that uses the default density.
size sets the size of every control that doesn't set its own, so an app whose controls are all size 3 says so once. It doesn't affect type: Text and Heading have their own nine-step scale, and Code, Kbd, Badge and Chip take the size of the line they sit in.
contrast="high" is an accessibility setting that strengthens borders, fills and text so they meet the contrast minimums. Put it on the same element as an appearance other than inherit. When contrast is unset, the theme follows the operating system's prefers-contrast: more setting.
A Theme renders a <div> to hold its settings, and render puts them on an element you already have instead. Never render the root Theme onto <body> or <html>, because menus, dialogs and other floating panels are added to the body.
Props
Generated from the types. It lists what this component DECLARES: a prop that arrives from a shared type or from the platform is real and is not repeated here.
| Prop | Type | What it does |
|---|---|---|
accent? | "blue" | "purple" | "pink" | "orange" | "amber" | "green" | Gives this scope its own accent colour: blue, purple, pink, orange, amber or green. |
appearance? | "inherit" | "light" | "dark" | Sets the colour scheme for this scope: light, dark or inherit. |
children? | React.ReactNode | The content that this theme applies to. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
contrast? | "normal" | "high" | Turns on high contrast for this scope: normal or high. |
density? | "compact" | "default" | "comfortable" | Sets how much space the app gives its controls: compact, default or comfortable. |
depth? | "flat" | "elevated" | Sets whether surfaces and raised controls cast shadows: elevated or flat. |
material? | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | Sets the material for every component in this scope. |
pointer? | "fine" | "coarse" | "auto" | Sets the input type for this scope: fine, coarse or auto. |
radius? | "none" | "small" | "medium" | "large" | "full" | Sets the corner radius for the app: none, small, medium, large or full. |
render? | RenderElement | Renders the theme on an element that you supply, instead of an extra wrapper element. |
size? | "1" | "2" | "3" | "4" | Sets the default size step for every sized component in this scope. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
- An
accentColorprop — The accent is one colour for the whole app, set in the colour config, and the full palette is generated from it. A prop that changed it at runtime would mean shipping every possible colour scale. - A
scalingprop — Multiplying every size by one factor breaks the designed relationships between them. Usedensity, which switches to designed values for tighter or roomier layouts. - A shadow or elevation prop on components — Shadows are a choice for the whole app, so individual components have no shadow prop. Use
depthon the Theme to turn them on or off. - An outlined or filled style — Cards and fields have one appearance, so screens built by different people match. Use
depthto choose between raised and flat surfaces.