Skip to content

Material 3

Theme

Accessibility

Touch targets, forced colors, contrast and reduced motion.

Use the theme's accessibility classes for a target large enough to press, an edge and a selection that survive forced colors, and color pairs that hold at raised contrast. The theme's motion stops when asked with no class at all, and one class shows the focus ring.

ForUse
A 48dp target on a smaller controltouch-target
An edge for a container in forced colorsforced-colors:container-border
A fill for a selected control in forced colorsforced-colors:selected-fill
A color pair that holds at medium and high contrastcontrast-raised:
Motion that stops when askedThe theme's durations
A visible keyboard focusfocus-ring

Touch targets

touch-target extends a small control's hit area to the 48dp Material minimum without changing its visual size. Put it on a positioned element, relative touch-target. A control already 48dp or larger is unaffected.

The 24dp button below can be pressed from anywhere in the dashed circle, which is shown here to mark the target.

Pressed 0 times
import { useState } from 'react'

export default function TouchTarget() {
  const [count, setCount] = useState(0)
  return (
    <div className="flex items-center gap-space-600">
      <button
        type="button"
        aria-label="Add one"
        className="touch-target relative focus-ring size-6 cursor-pointer rounded-shape-full border-0 bg-primary after:rounded-shape-full after:outline after:outline-outline-variant after:outline-dashed"
        onClick={() => setCount(count + 1)}
      />
      <span className="text-body-lg">Pressed {count} times</span>
    </div>
  )
}
  • Spacing: The targets of two small controls overlap where the controls are less than 48dp apart, center to center. Material recommends 8dp or more of space between targets.
  • Clipping: The target reaches past the control's edge, so overflow-hidden on the control cuts it back to the control's size.
  • Pseudo-element: The target is the control's ::after. For a decoration of your own on the same control, use before:.
  • Density: The target stays 48dp on a control made smaller by a density.
  • Components: The library's small controls, such as a Checkbox, a Switch or an extra small IconButton, have the class already.

Forced colors

In forced colors mode, Windows' contrast themes, the browser drops backgrounds and shadows and paints in the system colors. Use two utilities to keep what would be lost, each with Tailwind's forced-colors: variant.

ClassUseDraws
forced-colors:container-borderA container, which has no edge left without its fill and shadowA 1dp border in the system's button text color, gray text when disabled
forced-colors:selected-fillA selected toggle, or a checkbox's box, which would otherwise look unselectedA fill in the system highlight colors, the gray ones when disabled
<div class="bg-surface-container-low shadow-elevation-1 forced-colors:container-border"></div>
<button
  aria-pressed="true"
  class="aria-pressed:bg-secondary-container forced-colors:aria-pressed:selected-fill"
></button>
  • Border width: The border of container-border takes room, 1dp on each side of the container.
  • Disabled: Both classes follow the element's disabled: variant, which matches a disabled React Aria component with React Aria's plugin.

System colors

Use the system colors as colors too, for an element that keeps a border or a fill in that mode and only needs it recolored, as in forced-colors:border-gray-text. Each is a Tailwind theme variable, so its name works after any color utility. See Color.

Color and theme variableSystem colorUse
canvas
--color-canvas
CanvasThe background of the page
canvas-text
--color-canvas-text
CanvasTextText on the page
gray-text
--color-gray-text
GrayTextDisabled text
highlight
--color-highlight
HighlightThe background of what is selected
highlight-text
--color-highlight-text
HighlightTextThe text of what is selected

These five are the only tokens of the theme's accessibility classes. The focus ring's are under State, and the durations that reduced motion sets under Motion.

Raised contrast

Set data-contrast="medium" or "high" to raise the contrast of every color role. See Color. Use the contrast-raised: variant to style an element inside such a scope, for a role pair that holds 3:1 at standard contrast only, such as a primary icon on secondary-container: contrast-raised:text-on-secondary-container.

<span
  class="bg-secondary-container text-primary contrast-raised:text-on-secondary-container"
></span>
  • Scope: The variant matches the element that has data-contrast, and every element inside it.
  • System setting: The contrast level comes from the attribute alone. To style for the system's contrast setting, use Tailwind's contrast-more: variant.

Reduced motion

With prefers-reduced-motion, every duration token, a spring's too, is next to nothing. Whatever runs on the theme's motion tokens is instant, with no extra class.

A transition on one of Tailwind's own durations still runs, and so does a custom duration set outside the media query. See Motion.

Focus ring

Add focus-ring to show the Material focus indicator for keyboard focus alone. See State.