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

```typescript
import 'material/styles';
```

Or the base, then the components you use:

```typescript
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:

```typescript
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.** `base` works everywhere. A page of web components only can take `base-elements`, since each
  shadow root has its own ripple, or `base-lite`, without the reset and the contrast modes. Factories, and `data-ripple`
  on the page, need `base`.
- **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](https://md3.io/develop/scaffold.md), 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](https://md3.io/develop/tailwind.md). To change a component's look, set its custom properties; for the theme, see [Theming](https://md3.io/styles/theming.md).

## Compile them yourself

The Sass sources ship in `material/src/styles`: the [Sass configuration](https://md3.io/styles/theming.md#sass-configuration) covers the
switches, and [Web Components](https://md3.io/develop/web-components.md#application-compiled-element-styles) the shadow styles. One that
changes the size most is the contrast rules:

```scss
@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.
