Search
HomeGet startedDevelopStylesComponents

Installation

Install the package, import the styles, render a component.

PublishedUpdated

material is a Material Design 3 component library for the web, with no dependencies. The same components work as plain JavaScript factories, as web components, and as React, Vue, Svelte and Solid components. This page takes you from install to a first component; the chips at the top show every step and example in the way you use it.

FactoryWeb ComponentsReactVueSvelteSolid

For coverage, measured sizes, browser support and the current limits, see Why material.

Install

bun add material
npm install material
pnpm add material
yarn add material
bun add material@next
npm install material@next
pnpm add material@next
yarn add material@next

React, Vue, Svelte and Solid are optional peer dependencies: material uses the one your app already has, and installs none of them itself.

Choose how to use it

Way Import from Good for
Vanilla material The smallest bundles, full control, any stack
Web Components material/elements Plain HTML, server templates, any framework
React material/react React 18 and 19, Next.js
Vue material/vue Vue 3, Nuxt
Svelte material/svelte Svelte 5, SvelteKit
Solid material/solid Solid, SolidStart

The web components are built on the factories, and the framework components render the web components, so they all look and behave alike. Pick yours with the chips at the top: the steps below follow it, and Frameworks has its guide.

Each web component styles its own shadow root, which costs more on a first render than the same component as a factory: 1,000 text fields mount in about 290 ms as elements against about 150 ms as factories, and with the CPU slowed four times in about 1.4 s against about 0.63 s (material 3.0.0-next.0, Chromium 153, medians of 15 runs). A form or a page has far fewer. For hundreds of instances at once, such as a long editable table, use the Vanilla factories. See Web Components.

Add the styles

Every app loads one base stylesheet. For factories, use the full base; add material/styles/typography for the type scale:

import 'material/styles/base';
import 'material/styles/typography';

For element and framework applications, choose the base that fits the page:

Entry Includes
material/styles/base Theme, tokens, reset, system contrast and global ripple rules; needed for factories and page-level data-ripple
material/styles/base-elements Baseline light/dark theme, colour/shape/typeface tokens, reset, cascade order and system contrast (prefers-contrast: more); no global ripple rules
material/styles/base-lite Theme, tokens, body theme and reduced-motion switch; no reset, ripple or contrast modes

Elements carry ripple CSS in their shadow roots, so bundled base-elements CSS saves 293 B gzip (970 B raw) against base. Explicit data-theme-contrast still needs material/styles/contrast. The typography JavaScript entry brings in the full base; Theming explains loading typography CSS separately when keeping the smaller base.

With the Vanilla factories, also import each component's stylesheet:

import 'material/styles/button';

The web components carry their own styles in their shadow roots, so no page-level component stylesheets are needed. Register them once:

import 'material/elements/css';
import { defineAll } from 'material/elements';

defineAll();

The React components carry their own styles in their shadow roots, so no page-level component stylesheets are needed. Import them from material/react; each registers the element it renders the first time it mounts.

The Vue components carry their own styles in their shadow roots, so no page-level component stylesheets are needed. Import them from material/vue; each registers the element it renders the first time it mounts.

The Svelte components carry their own styles in their shadow roots, so no page-level component stylesheets are needed. Import them from material/svelte; each registers the element it renders the first time it mounts.

The Solid components carry their own styles in their shadow roots, so no page-level component stylesheets are needed. Import them from material/solid; each registers the element it renders the first time it mounts.

A first component

A filled button that saves when it is clicked:

Vanilla
import { createButton } from 'material';

const button = createButton({ text: 'Save', variant: 'filled' });
button.on('click', () => save());
document.body.append(button.element);
Web Components
<m-button variant="filled">Save</m-button>

<script type="module">
  const button = document.querySelector('m-button');
  button.addEventListener('click', () => save());
</script>
React
import { Button } from 'material/react';
import { save } from './app';

export function Example() {
  return (
    <Button onClick={() => save()} variant="filled">Save</Button>
  );
}
Vue
<script setup lang="ts">
import { MButton } from 'material/vue';
import { save } from './app';
</script>

<template>
  <MButton @click="save()" variant="filled">Save</MButton>
</template>
Svelte
<script lang="ts">
  import { Button } from 'material/svelte';
  import { save } from './app';
</script>

<Button onclick={() => save()} variant="filled">Save</Button>
Solid
import { Button } from 'material/solid';
import { save } from './app';

export function Example() {
  return (
    <Button onClick={() => save()} variant="filled">Save</Button>
  );
}

Every component page has the same kind of example, and a playground to try the options.

Themes and dark mode

The base stylesheet has the baseline theme. Another theme is one more import, and it applies to the element that names it, usually the whole page:

import 'material/themes/vibrant';

document.documentElement.dataset.theme = 'vibrant';
document.documentElement.dataset.themeMode = 'dark';

Browse the themes and every colour role in Styles › Color, and see Theming to make your own.

Next steps

  • Components: every component in a playground, with the code for your framework.
  • Frameworks: the guide for your framework, for its events, forms and server rendering.
  • Architecture: how material is built.