Skip to content

Material 3

Theme

Layout

Breakpoints, stacking order and scrollbars.

Use Material's five breakpoints as Tailwind variants, such as expanded-screen:, to change a layout with the width of the window, and the stacking order classes for the surfaces that overlap. The theme also styles the scrollbar.

Breakpoints

The theme's breakpoints follow Material's breakpoints, which it named window size classes before: the window widths at which a layout changes. They are min-width breakpoints, next to Tailwind's own. Write the styles of a compact window with no prefix, and use a variant for each breakpoint from medium up. Resize the window to see them take effect.

compactmedium-screen:expanded-screen:large-screen:extra-large-screen:
import { twMerge } from '@material-web/react'

const size = 'rounded-shape-sm px-space-150 py-space-100 text-label-lg'
const off = 'bg-surface-container-high text-on-surface-variant'

export default function Breakpoints() {
  return (
    <>
      <span className={twMerge(size, 'bg-primary text-on-primary')}>compact</span>
      <span
        className={twMerge(size, off, 'medium-screen:bg-primary medium-screen:text-on-primary')}
      >
        medium-screen:
      </span>
      <span
        className={twMerge(size, off, 'expanded-screen:bg-primary expanded-screen:text-on-primary')}
      >
        expanded-screen:
      </span>
      <span className={twMerge(size, off, 'large-screen:bg-primary large-screen:text-on-primary')}>
        large-screen:
      </span>
      <span
        className={twMerge(
          size,
          off,
          'extra-large-screen:bg-primary extra-large-screen:text-on-primary',
        )}
      >
        extra-large-screen:
      </span>
    </>
  )
}
VariantBreakpointFromCommon devices
noneCompact0Phone in portrait
medium-screen:Medium600dpTablet in portrait, foldable in portrait (unfolded)
expanded-screen:Expanded840dpPhone in landscape, tablet in landscape, foldable in landscape (unfolded), desktop
large-screen:Large1200dpDesktop
extra-large-screen:Extra-large1600dpDesktop, ultra-wide monitors

A breakpoint variant is one of Tailwind's responsive variants, and is used like any other:

  • Wider windows: A variant applies from its width up: expanded-screen: also applies in a large window.
  • Ranges: Each has its max- form, as Tailwind's breakpoints do: max-medium-screen: matches a compact window alone. Use both for a range, as in medium-screen:max-large-screen:flex.
  • Names: The variants end in -screen: expanded: without it matches an expanded element, not a window size.
  • Tailwind's breakpoints: Keep to one set of breakpoints on an element. Tailwind's own breakpoints override Material's whatever their sizes, so md: overrides expanded-screen: though it is the narrower.
  • Your own CSS: Use a breakpoint in a stylesheet with Tailwind's @variant, as in @variant expanded-screen { ... }.
  • Panes and navigation: Material moves a layout from one pane to two or three as the window widens, and swaps the navigation bar of a compact window for a navigation rail from medium up.

Stacking order

Use these classes to stack the surfaces that overlap, lowest to highest, so that any two of them agree: a menu in a dialog, a snackbar over a sheet.

Classz-indexSurface
z-fab10A floating action button
z-app-bar20An app bar
z-navigation30A navigation bar or rail
z-scrim40The scrim behind a modal surface
z-sheet50A sheet
z-dialog60A dialog
z-menu70A menu
z-snackbar80A snackbar
z-tooltip90A tooltip

Inside a component, under all of them, use three more classes for its parts:

Classz-indexPart
z-behind-1A part behind its content
z-raised1A part raised above its siblings
z-focus-ring5The focused element, so that nothing next to it covers its ring

A stacking class is one of Tailwind's z-index utilities, and is used like any other:

  • Components: The library's surfaces, such as a Dialog, a Menu or a Snackbar, have their class already.
  • Tailwind's z-index: Tailwind's numeric classes are unchanged, and are on the same scale: z-10 is level with z-fab.
  • Parts of a component: Add Tailwind's isolate to a component's root, so that the order of its parts stays inside it.
  • Merged classes: tailwind-merge does not know the order, and keeps both of two stacking classes. To merge them, use the tv or the twMerge that @material-web/react exports, where the later class replaces the earlier one.

Scrollbar

The theme gives every scroll container and the page the Material scrollbar: a 4dp thumb in the outline color with round ends and no track. Firefox shows its own thin scrollbar in that color.

Use scrollbar-hidden to hide a scrollbar without disabling the scrolling, for an overflow that should read as clipped content.

<div class="scrollbar-hidden overflow-x-auto"></div>

The scrollbar is styled in Tailwind's base layer, so a scrollbar rule in your own CSS replaces it.

Custom layout

The breakpoints and the stacking order are Tailwind theme variables. Set them in @theme, after the import:

@import 'tailwindcss';
@import '@material-web/tailwind';

@theme {
  --breakpoint-medium-screen: 640px;
  --z-index-dialog: 100;
}
Theme variableDefaultComponents that use it, such as
--breakpoint-medium-screen600pxDialog
--breakpoint-expanded-screen840pxNone
--breakpoint-large-screen1200pxNone
--breakpoint-extra-large-screen1600pxNone
--z-index-fab10FAB, FAB menu
--z-index-app-bar20App bar
--z-index-navigation30None
--z-index-scrim40None
--z-index-sheet50Bottom sheet
--z-index-dialog60Dialog, modal sheets, search view
--z-index-menu70Menu
--z-index-snackbar80Snackbar
--z-index-tooltip90None
--z-index-behind-1Text field
--z-index-raised1App bar, calendar, chip, list, slider
--z-index-focus-ring5Every component with a focus ring
  • Units: Keep a breakpoint in px. Tailwind sorts the breakpoints of one unit together, so one in rem no longer comes in the order of its size.
  • Breakpoint of your own: Add a variable for a breakpoint of your own, as in --breakpoint-tv: 1920px for a tv: variant.
  • Surface of your own: Add a variable to place a surface in the order, as in --z-index-banner: 25 for a z-banner class between the app bar and the navigation.