Stylesheets
Which stylesheet to import, and what each one holds. The web components and the framework components carry their own styles in their shadow roots: they need only a base, for the theme and its tokens. The factories render in the page, so they need the page's stylesheets.
Factories: all, or only what you use
Import everything once:
import 'material/styles';
Or the base, then the components you use:
import 'material/styles/base';
import 'material/styles/button';
import 'material/styles/text-field';
// Another theme, and the utility classes, if you want them
import 'material/themes/ocean';
import 'material/styles/utilities';
One way or the other, not both. Each entry imports what it depends on (the select brings the text field and the menu), and a bundler keeps one copy. These entries import CSS, so they do not load in plain Node.
A page whose factory buttons all stay filled, small and round can use a smaller sheet in place of the button's:
import 'material/styles/base';
import 'material/styles/button-filled-small-round';
import createButton from 'material/components/button';
const save = createButton({ text: 'Save', variant: 'filled', size: 's', shape: 'round' });
document.body.append(save.element);
Any other variant, size or shape, set later too, needs material/styles/button. Tabs, cards and other components may
already bring that one; the small sheet is then only extra.
What each one holds
| Import | Holds |
|---|---|
material/styles/base |
The baseline theme in light and dark, the colour, shape and typeface tokens, a reset and the ripple |
material/styles/base-elements |
The same without the page's ripple rules: for pages of web components |
material/styles/base-lite |
The theme, its tokens, the body theme and the reduced-motion switch; no reset, ripple or contrast modes |
material/styles/contrast |
The baseline's medium and high contrast, for explicit contrast attributes |
material/styles/typography |
The type scale, its classes (.mtrl-display-large to .mtrl-label-small), the text utilities, headings and paragraphs |
material/styles/utilities |
The utility classes |
material/styles/<component> |
One component, with what it depends on |
material/styles |
The standard components, typography, and the twelve themes with their contrast levels |
- One base per page.
baseworks everywhere. A page of web components only can takebase-elements, since each shadow root has its own ripple, orbase-lite, without the reset and the contrast modes. Factories, anddata-rippleon the page, needbase. - Typography is for pages that use the type classes or material's headings, or read a
--mtrl-sys-typescale-*token in their own CSS. It loads after the base, which its import takes care of. - Opt-in components, such as the scaffold, have their own stylesheets and are in none of these.
Your CSS wins
The base and the per-component stylesheets are in ordered mtrl.* cascade layers, so your own unlayered CSS overrides
them whatever its specificity. material/styles is in no layer: there, specificity and order decide. With Tailwind,
see Tailwind CSS. To change a component's look, set its custom properties; for the theme, see Theming.
Compile them yourself
The Sass sources ship in material/src/styles: the Sass configuration covers the
switches, and Web Components the shadow styles. One that
changes the size most is the contrast rules:
@use "material/src/styles/themes" with ($contrast-emit: none);
$contrast-emit |
Rules beside the standard light and dark roles |
|---|---|
all (default) |
Medium and high contrast, by attribute and by the system's preference |
explicit |
By attribute only |
preference |
By the system's preference only |
none |
None: the page answers neither |
The stylesheet you import ready-made keeps them all.