made android client

This commit is contained in:
2026-10-17 04:01:58 +03:00
parent 19ee41411b
commit e1a787c1dd
59 changed files with 9379 additions and 1 deletions

View File

@@ -0,0 +1,18 @@
{
"name": "material-3",
"version": "1.1.1",
"description": "Material Design 3 (Material You) implementation skill for Jetpack Compose, Flutter, and web.",
"author": {
"name": "Ivan Morgillo"
},
"repository": "https://github.com/hamen/material-3-skill",
"license": "MIT",
"keywords": [
"material-design",
"material3",
"jetpack-compose",
"flutter",
"android",
"ui"
]
}

View File

@@ -0,0 +1,667 @@
---
name: material-3
description: >
Implement Google's Material Design 3 (Material You) UI system. Primary: Jetpack Compose
Material3 (MaterialTheme, components, adaptive layout). Also Flutter and limited web
(@material/web, maintenance mode). Covers tokens, 30+ components, layout, theming,
M3 Expressive (platform matrix), and accessibility. Use when: "material design", "MD3",
"material you", "Jetpack Compose", "MaterialTheme", "material component", "md3 button".
user-invokable: true
argument-hint: "[component|theme|layout|scaffold|audit] [description or URL]"
---
# Material Design 3
This skill guides implementation of Google's Material Design 3 (MD3) — a personal, adaptive, expressive design system. MD3 uses dynamic color, tonal surfaces, rounded shapes, and spring-based motion to create UIs that feel alive and personal.
## Philosophy
MD3 is built on three principles:
- **Personal**: Dynamic color adapts UI to the user's wallpaper or content. Theming is individual, not one-size-fits-all.
- **Adaptive**: Layouts transform across 5 window size classes. Components resize, reposition, and change form factor responsively.
- **Expressive**: Shape morphing, spring physics, and emphasized typography create moments of delight without sacrificing usability.
## Current Updates: Google I/O 2026
Material's [Google I/O 2026 update](https://m3.material.io/blog/whats-new-at-io26) reinforces a **Compose-first** Android path and expands expressive/adaptive guidance:
- **Material Android is Compose-first**: For new Android work, prefer Jetpack Compose Material3 for the latest components, expressive APIs, adaptive scaffolds, and Styles API integration. Android Views may remain necessary in existing apps, but they should not be treated as the default path for new Material 3 implementations.
- **Expressive layout system**: Use an expressive layout scaffold to adapt screens across mobile, desktop, foldables, watches, XR, and other spatial form factors. Start from adaptive scaffolds/window size classes instead of fixed phone-first layouts.
- **8dp spacing system**: Apply spacing tokens for margins, padding, and gaps so layouts and components can adapt programmatically to device type and density.
- **New/updated expressive components**: Lists, menus, search, and search app bars have refreshed expressive guidance, with Jetpack Compose as the primary implementation target.
- **Watches and XR**: Watches emphasize physics-based motion, arc text, and edge-hugging containers. XR emphasizes spatial panels and depth-based elevation.
**Key differences from MD2:**
- Tonal surfaces replace elevation shadows as the primary depth cue
- Dynamic color generates full schemes from a single seed color
- Fully rounded corners by default (not slightly rounded)
- Spring-based motion physics replace fixed easing curves for components
- 3 levels of user-controlled contrast (standard/medium/high)
**Relationship with frontend-design skill:**
When both skills are active, MD3 provides the design system (tokens, components, layout rules) and frontend-design provides creative direction within those constraints. MD3 rules take precedence for component structure and token usage. Note: Roboto/Roboto Flex IS the correct default typeface in MD3 — the frontend-design guidance to avoid Roboto does not apply when implementing MD3.
## Decision Tree
**What are you building?**
```
Full app scaffold → See "Common Patterns: App Shell" + references/layout-and-responsive.md
Single component → See "Component Quick Reference" table → references/component-catalog.md
Custom theme → See references/theming-and-dynamic-color.md
Form / input layout → See references/component-catalog.md § Input Components
Navigation structure → See references/navigation-patterns.md
Data display → See references/component-catalog.md § Data Display
```
**What platform?**
```
Jetpack Compose → Primary: androidx.compose.material3, MaterialTheme, references/*
Flutter → useMaterial3: true in ThemeData, ColorScheme.fromSeed()
Web (vanilla JS) → @material/web (limited; maintenance mode) + CSS custom properties
Web (React/Vue/Svelte) → CSS custom properties + wrapper components (no official React lib)
Web (CSS-only) → MD3 token values as CSS custom properties (no <md-*> elements)
```
## Design Token System
All MD3 tokens use the `md.sys` namespace. **Jetpack Compose** maps roles to `MaterialTheme.colorScheme`, `MaterialTheme.typography`, and `MaterialTheme.shapes` (same semantic roles as the spec). **On the web**, these map to CSS custom properties (`--md-sys-*`):
### Color Tokens (`--md-sys-color-*`)
| Token | Purpose |
|-------|---------|
| `primary` | High-emphasis fills, text, icons against surface |
| `on-primary` | Text/icons on primary |
| `primary-container` | Standout fill for key components (FAB, etc.) |
| `on-primary-container` | Text/icons on primary-container |
| `secondary` / `on-secondary` | Less prominent accents |
| `secondary-container` / `on-secondary-container` | Recessive components (tonal buttons) |
| `tertiary` / `on-tertiary` | Contrasting accents |
| `tertiary-container` / `on-tertiary-container` | Complementary containers |
| `error` / `on-error` | Error states (static — doesn't change with dynamic color) |
| `error-container` / `on-error-container` | Error container fills |
| `surface` | Default background |
| `on-surface` | Text/icons on any surface |
| `on-surface-variant` | Lower-emphasis text/icons on surface |
| `surface-container-lowest` | Lowest-emphasis container |
| `surface-container-low` | Low-emphasis container |
| `surface-container` | Default container (nav areas) |
| `surface-container-high` | High-emphasis container |
| `surface-container-highest` | Highest-emphasis container |
| `surface-dim` / `surface-bright` | Maintain relative brightness across light/dark |
| `inverse-surface` / `inverse-on-surface` / `inverse-primary` | Contrasting elements (snackbars) |
| `outline` | Important boundaries (text field borders) |
| `outline-variant` | Decorative elements (dividers) |
Full details: `references/color-system.md`
### Typography Tokens (`--md-sys-typescale-*`)
| Scale | Sizes | Use |
|-------|-------|-----|
| Display | L / M / S | Hero text, large numbers |
| Headline | L / M / S | Section headers |
| Title | L / M / S | Smaller headers, card titles |
| Body | L / M / S | Paragraph text, descriptions |
| Label | L / M / S | Buttons, chips, captions |
Each style has tokens for: `-font`, `-weight`, `-size`, `-line-height`, `-tracking`
Plus 15 **emphasized** variants (higher weight) via `--md-sys-typescale-emphasized-*`
Full details: `references/typography-and-shape.md`
### Shape Tokens (`--md-sys-shape-corner-*`)
| Token | Value | Example components |
|-------|-------|-------------------|
| `none` | 0dp | — |
| `extra-small` | 4dp | Chips, snackbars |
| `small` | 8dp | Text fields, menus |
| `medium` | 12dp | Cards |
| `large` | 16dp | FABs, navigation drawer |
| `large-increased` | 20dp | (Expressive) |
| `extra-large` | 28dp | Dialogs, bottom sheets |
| `extra-large-increased` | 32dp | (Expressive) |
| `extra-extra-large` | 48dp | (Expressive) |
| `full` | 9999px | Buttons, chips, badges |
### Elevation Levels
| Level | DP | Tonal offset | Use |
|-------|-----|-------------|-----|
| 0 | 0dp | None | Flat surfaces, most components at rest |
| 1 | 1dp | +5% primary | Elevated cards, modal sheets |
| 2 | 3dp | +8% primary | Menus, nav bar, scrolled app bar |
| 3 | 6dp | +11% primary | FAB, dialogs, search, date/time pickers |
| 4 | 8dp | +12% primary | (hover/focus increase only) |
| 5 | 12dp | +14% primary | (hover/focus increase only) |
Elevation in MD3 is communicated through **tonal surface color**, not shadows. Shadows are only used when needed for additional protection against busy backgrounds.
### Motion
MD3 Expressive (May 2025) introduced **spring-based motion physics** for components. The legacy easing/duration system is still used for **transitions** (enter/exit/shared-axis):
| Easing | Duration | Transition type |
|--------|----------|-----------------|
| Emphasized | 500ms | Begin and end on screen |
| Emphasized decelerate | 400ms | Enter the screen |
| Emphasized accelerate | 200ms | Exit the screen |
| Standard | 300ms | Begin and end on screen (utility) |
| Standard decelerate | 250ms | Enter screen (utility) |
| Standard accelerate | 200ms | Exit screen (utility) |
CSS easing values:
- Emphasized: `cubic-bezier(0.2, 0, 0, 1)`
- Emphasized decelerate: `cubic-bezier(0.05, 0.7, 0.1, 1)`
- Emphasized accelerate: `cubic-bezier(0.3, 0, 0.8, 0.15)`
- Standard: `cubic-bezier(0.2, 0, 0, 1)`
- Standard decelerate: `cubic-bezier(0, 0, 0, 1)`
- Standard accelerate: `cubic-bezier(0.3, 0, 1, 1)`
## Component Quick Reference
| Component | Web Element | Key Variants | Category |
|-----------|------------|--------------|----------|
| Button | `md-filled-button`, `md-outlined-button`, `md-text-button`, `md-elevated-button`, `md-filled-tonal-button` | Filled, Outlined, Text, Elevated, Tonal; 5 sizes (XS–XL); toggle | Actions |
| Button group | `md-button-group` | Standard, connected | Actions |
| Extended FAB | `md-extended-fab` | Surface, Primary, Secondary, Tertiary | Actions |
| FAB | `md-fab` | Small, Medium, Large | Actions |
| FAB menu | — | — | Actions |
| Icon button | `md-icon-button`, `md-filled-icon-button`, `md-filled-tonal-icon-button`, `md-outlined-icon-button` | Standard, Filled, Filled Tonal, Outlined | Actions |
| Segmented button | — | Single-select, Multi-select | Actions |
| Split button | — | — | Actions |
| Badge | — | Small (dot), Large (count) | Communication |
| Loading indicator | — | Linear, Circular | Communication |
| Progress indicator | `md-linear-progress`, `md-circular-progress` | Linear, Circular; determinate/indeterminate | Communication |
| Snackbar | — | Single-line, Two-line, Action | Communication |
| Tooltip | — | Plain, Rich | Communication |
| Card | — | Filled, Outlined, Elevated | Containment |
| Carousel | — | Multi-browse, Uncontained, Hero | Containment |
| Dialog | `md-dialog` | Basic, Full-screen | Containment |
| Bottom sheet | — | Standard, Modal | Sheets |
| Side sheet | — | Standard, Modal | Sheets |
| Divider | `md-divider` | Full-width, Inset | Containment |
| Checkbox | `md-checkbox` | — | Input |
| Chips | `md-chip-set`, `md-assist-chip`, `md-filter-chip`, `md-input-chip`, `md-suggestion-chip` | Assist, Filter, Input, Suggestion | Input |
| Date picker | — | Docked, Modal, Range | Input |
| Menu | `md-menu`, `md-menu-item` | — | Input |
| Radio button | `md-radio` | — | Input |
| Slider | `md-slider` | Continuous, Discrete, Range | Input |
| Switch | `md-switch` | With/without icon | Input |
| Text field | `md-filled-text-field`, `md-outlined-text-field` | Filled, Outlined | Input |
| Time picker | — | Docked, Modal | Input |
| App bar (top) | — | Center-aligned, Small, Medium, Large | Navigation |
| Navigation bar | `md-navigation-bar` | — | Navigation |
| Navigation drawer | `md-navigation-drawer` | Standard, Modal | Navigation |
| Navigation rail | — | — | Navigation |
| Search | — | Search bar, Search view | Navigation |
| Tabs | `md-tabs`, `md-primary-tab`, `md-secondary-tab` | Primary, Secondary | Navigation |
| Toolbar | — | — | Navigation |
| List | `md-list`, `md-list-item` | One-line, Two-line, Three-line | Data Display |
**Note:** Components marked with `—` for web element don't have @material/web implementations yet. Use CSS custom properties with standard HTML for these. **Compose** mappings and examples live in `references/component-catalog.md`.
Full component details with code examples: `references/component-catalog.md`
## Jetpack Compose (primary)
Use **`androidx.compose.material3`** with `MaterialTheme` and Material 3 composables (`Scaffold`, `Button`, `NavigationBar`, top app bars, etc.).
- **Theming**: `MaterialTheme(colorScheme = …, typography = …, shapes = …)`. Prefer `dynamicLightColorScheme` / `dynamicDarkColorScheme` on **Android 12+ (API 31+)** when dynamic color is desired; otherwise `lightColorScheme` / `darkColorScheme` or generated theme code from Material Theme Builder.
- **Adaptive UI**: Window size classes, list-detail and supporting-pane layouts, foldables — see `references/layout-and-responsive.md` and `references/navigation-patterns.md`.
- **Edge-to-edge & insets**: Lay out content with `WindowInsets` / scaffold padding so bars and IME behave correctly — see `references/layout-and-responsive.md`.
- **Experimental APIs**: Some Material 3 APIs require `@OptIn(ExperimentalMaterial3Api::class)` or expressive opt-ins; match your BOM and compiler.
```kotlin
MaterialTheme(
colorScheme = colorScheme, // from dynamicLightColorScheme / lightColorScheme / etc.
typography = Typography(),
shapes = Shapes(),
) {
// M3 content — prefer references for Scaffold, navigation, text fields
}
```
## Web (limited): @material/web
**Important:** Per [Material Design 3 for Web](https://m3.material.io/develop/web), **Material Web Components are in maintenance mode** and **M3 Expressive is not implemented on Web**. Use `@material/web` for token-backed web UIs when appropriate, but do not treat it as equivalent to Compose for current Expressive features.
### Setup
```bash
npm install @material/web
```
### Import Components Individually
Always import only the components you use — importing the entire package bloats the bundle:
```javascript
// Good — individual imports
import '@material/web/button/filled-button.js';
import '@material/web/button/outlined-button.js';
import '@material/web/textfield/outlined-text-field.js';
import '@material/web/icon/icon.js';
// Bad — never do this
import '@material/web'; // imports everything
```
### Basic Usage
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css2?family=Roboto+Flex:wght@400;500;700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Symbols+Outlined" rel="stylesheet">
</head>
<body>
<md-filled-button>Get started</md-filled-button>
<md-outlined-text-field label="Email" type="email"></md-outlined-text-field>
<script type="module">
import '@material/web/button/filled-button.js';
import '@material/web/textfield/outlined-text-field.js';
</script>
</body>
</html>
```
### Theming with CSS Custom Properties
Apply a custom theme by setting CSS custom properties on `:root` or any ancestor:
```css
:root {
/* Color scheme (generate with @material/material-color-utilities) */
--md-sys-color-primary: #6750A4;
--md-sys-color-on-primary: #FFFFFF;
--md-sys-color-primary-container: #EADDFF;
--md-sys-color-on-primary-container: #21005D;
--md-sys-color-secondary: #625B71;
--md-sys-color-on-secondary: #FFFFFF;
--md-sys-color-secondary-container: #E8DEF8;
--md-sys-color-on-secondary-container: #1D192B;
--md-sys-color-surface: #FEF7FF;
--md-sys-color-on-surface: #1D1B20;
--md-sys-color-surface-container: #F3EDF7;
--md-sys-color-outline: #79747E;
--md-sys-color-outline-variant: #CAC4D0;
/* Typography */
--md-sys-typescale-body-large-font: 'Roboto Flex', sans-serif;
--md-sys-typescale-body-large-size: 1rem;
--md-sys-typescale-body-large-weight: 400;
--md-sys-typescale-body-large-line-height: 1.5rem;
/* Shape */
--md-sys-shape-corner-full: 9999px;
--md-sys-shape-corner-medium: 12px;
}
```
### Component-Level Overrides
Override individual component tokens for specific customization:
```css
md-filled-button {
--md-filled-button-container-color: var(--md-sys-color-primary);
--md-filled-button-label-text-color: var(--md-sys-color-on-primary);
--md-filled-button-container-shape: var(--md-sys-shape-corner-full);
--md-filled-button-container-height: 40px;
}
md-outlined-text-field {
--md-outlined-text-field-container-shape: var(--md-sys-shape-corner-small);
--md-outlined-text-field-focus-outline-color: var(--md-sys-color-primary);
}
```
### Dark Theme
Apply dark theme by overriding color tokens on a class or media query:
```css
@media (prefers-color-scheme: dark) {
:root {
--md-sys-color-primary: #D0BCFF;
--md-sys-color-on-primary: #381E72;
--md-sys-color-primary-container: #4F378B;
--md-sys-color-on-primary-container: #EADDFF;
--md-sys-color-surface: #141218;
--md-sys-color-on-surface: #E6E0E9;
--md-sys-color-surface-container: #211F26;
--md-sys-color-outline: #938F99;
--md-sys-color-outline-variant: #49454F;
}
}
```
Full theming guide: `references/theming-and-dynamic-color.md`
## Common Patterns
### App Shell
Standard MD3 app with responsive navigation + top app bar + content area:
```html
<div class="md3-app">
<nav class="md3-nav-rail" aria-label="Main navigation">
<!-- Navigation rail for medium+ screens -->
<md-fab size="small" aria-label="Compose">
<md-icon slot="icon">edit</md-icon>
</md-fab>
<md-navigation-bar>
<md-navigation-tab label="Home">
<md-icon slot="active-icon">home</md-icon>
<md-icon slot="inactive-icon">home</md-icon>
</md-navigation-tab>
<md-navigation-tab label="Search">
<md-icon slot="active-icon">search</md-icon>
<md-icon slot="inactive-icon">search</md-icon>
</md-navigation-tab>
</md-navigation-bar>
</nav>
<main class="md3-content">
<header class="md3-top-app-bar">
<h1 class="md3-top-app-bar__title" style="font: var(--md-sys-typescale-title-large)">
Page Title
</h1>
</header>
<div class="md3-body">
<!-- Content here -->
</div>
</main>
</div>
```
```css
.md3-app {
display: flex;
min-height: 100vh;
background: var(--md-sys-color-surface);
color: var(--md-sys-color-on-surface);
}
.md3-nav-rail {
width: 80px;
background: var(--md-sys-color-surface);
border-right: 1px solid var(--md-sys-color-outline-variant);
display: flex;
flex-direction: column;
align-items: center;
padding-top: 12px;
gap: 12px;
}
.md3-content {
flex: 1;
display: flex;
flex-direction: column;
}
.md3-top-app-bar {
height: 64px;
padding: 0 16px;
display: flex;
align-items: center;
background: var(--md-sys-color-surface);
}
.md3-body {
padding: 24px;
flex: 1;
}
/* Responsive: switch to bottom nav on compact */
@media (max-width: 599px) {
.md3-app { flex-direction: column; }
.md3-nav-rail {
order: 1;
width: 100%;
flex-direction: row;
justify-content: center;
border-right: none;
border-top: 1px solid var(--md-sys-color-outline-variant);
padding: 0;
}
}
```
### Card Grid
```html
<div class="md3-card-grid">
<div class="md3-card md3-card--outlined">
<img src="image.jpg" alt="Description" class="md3-card__media">
<div class="md3-card__content">
<h3 style="font: var(--md-sys-typescale-title-medium)">Card Title</h3>
<p style="font: var(--md-sys-typescale-body-medium); color: var(--md-sys-color-on-surface-variant)">
Supporting text for this card.
</p>
</div>
<div class="md3-card__actions">
<md-text-button>Learn more</md-text-button>
<md-filled-tonal-button>Action</md-filled-tonal-button>
</div>
</div>
</div>
```
```css
.md3-card-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 16px;
}
.md3-card--outlined {
border: 1px solid var(--md-sys-color-outline-variant);
border-radius: var(--md-sys-shape-corner-medium, 12px);
background: var(--md-sys-color-surface);
overflow: hidden;
}
.md3-card__content { padding: 16px; }
.md3-card__actions { padding: 8px 16px 16px; display: flex; gap: 8px; justify-content: flex-end; }
.md3-card__media { width: 100%; aspect-ratio: 16/9; object-fit: cover; }
```
### Form Layout
```html
<form class="md3-form">
<md-outlined-text-field label="Full name" required></md-outlined-text-field>
<md-outlined-text-field label="Email" type="email" required></md-outlined-text-field>
<md-outlined-text-field label="Message" type="textarea" rows="4"></md-outlined-text-field>
<div class="md3-form__actions">
<md-text-button type="reset">Cancel</md-text-button>
<md-filled-button type="submit">Submit</md-filled-button>
</div>
</form>
```
```css
.md3-form {
display: flex;
flex-direction: column;
gap: 16px;
max-width: 560px;
}
.md3-form__actions {
display: flex;
gap: 8px;
justify-content: flex-end;
margin-top: 8px;
}
```
More patterns: `references/navigation-patterns.md`, `references/layout-and-responsive.md`
## Anti-Patterns
**Never do these when implementing MD3:**
- **Mix MD2 and MD3 libraries**: Don't use `@material/mdc-*` (MD2) alongside `@material/web` (MD3). They have incompatible APIs and styling.
- **Hardcode colors**: Always use `var(--md-sys-color-*)` tokens, never raw hex/rgb values. Hardcoded colors break dynamic theming, dark mode, and contrast adjustment.
- **Ignore tonal pairing**: Only combine colors in their intended pairs (e.g., `primary` + `on-primary`, `surface-container` + `on-surface`). Arbitrary pairings break contrast in dynamic color and high contrast modes.
- **Use `outline` for dividers**: Use `outline-variant` for dividers. `outline` is for important boundaries like text field borders.
- **Import all of @material/web**: Always import individual component modules. Barrel imports include every component and destroy bundle size.
- **Use `border-radius` directly**: Use shape tokens (`var(--md-sys-shape-corner-medium)`) so shapes stay consistent with theming.
- **Use shadows for elevation by default**: MD3 communicates elevation through tonal surface color, not shadows. Only add shadows when elements need extra separation from busy backgrounds.
- **Apply frontend-design "avoid Roboto" rule**: On **Android**, **Roboto** is the default Material typeface; **web** often uses Roboto or Roboto Flex with MD3 tokens. Replace only when intentionally customizing the type scale.
- **Assume SSR compatibility**: `@material/web` uses Web Components (custom elements) which require JavaScript to render. They won't produce meaningful HTML in SSR without additional hydration strategies.
- **Ignore foldables and large screens**: MD3 is designed for all screen sizes. Don't ship phone-only layouts — use canonical layouts, multi-pane at 600dp+, and test on foldable/tablet emulators. Place no interactive content across the fold/hinge.
- **Stretch content to fill wide screens**: On Large (1200dp+) and Extra-large (1600dp+) windows, constrain content to a max width (840–1040dp). Endless-width text lines are unreadable.
## Platform Notes
### Flutter
```dart
MaterialApp(
theme: ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
),
);
```
### Jetpack Compose
See **[Jetpack Compose (primary)](#jetpack-compose-primary)** above. Use `LocalContext.current` with `dynamicLightColorScheme` / `dynamicDarkColorScheme` only when `Build.VERSION.SDK_INT >= Build.VERSION_CODES.S` and dynamic color is enabled; otherwise supply static light/dark schemes.
### Component Name Mapping
| Concept | Web | Flutter | Compose |
|---------|-----|---------|---------|
| Filled button | `md-filled-button` | `FilledButton` | `Button` |
| Outlined text field | `md-outlined-text-field` | `OutlinedTextField` | `OutlinedTextField` |
| FAB | `md-fab` | `FloatingActionButton` | `FloatingActionButton` |
| Navigation bar | `md-navigation-bar` | `NavigationBar` | `NavigationBar` |
| Switch | `md-switch` | `Switch` | `Switch` |
## M3 Expressive (May 2025)
The Expressive update adds visual richness while maintaining usability. **Availability differs by platform** — do not assume one stack implements everything.
| Capability | Jetpack Compose | Flutter | Web (`@material/web`) |
|------------|-----------------|---------|------------------------|
| Expressive layout scaffold / adaptive layout | Compose-first via Material3 adaptive APIs and window size classes | Use Flutter adaptive/layout primitives | CSS/container queries/manual layout; no Material Web parity |
| 8dp spacing system | Use design tokens / `Dp` spacing constants; keep margins, padding, and gaps adaptive | Use theme spacing constants | CSS custom properties / design tokens |
| Expressive lists, menus, search, search app bar | Primary target per current Material guidance; check BOM and opt-ins | Check current Flutter Material docs | Spec-aligned custom implementation; `@material/web` is maintenance-only |
| Spring / motion physics | Supported in Material 3 (see `MotionScheme`, expressive APIs per BOM) | Varies by Flutter Material version | **Not** in Material Web; use easing/duration or custom motion |
| Emphasized typography | Via theme / type scale | Via theme | Token/CSS only; no full Expressive component set |
| Shape morphing | Compose-first in Google’s expressive rollout | Check current Flutter docs | **Not** in `@material/web` |
| New button sizes (XS–XL), toggle | Follow Compose Material3 components | Follow Flutter MD3 | Height/CSS approximations only |
| Extra corner tokens (e.g. large-increased) | `MaterialTheme.shapes` / tokens | Theme shapes | CSS `--md-sys-shape-*` |
| 3 contrast levels | Scheme builders / system | Plugins / manual | `SchemeContent` contrast parameter in JS utilities |
| Watches / XR form factors | Use Compose/Wear/XR-specific guidance where available | Platform-specific | Web/spatial UI custom implementation |
**Web:** [Material Web is maintenance-only; M3 Expressive is not on Web](https://m3.material.io/develop/web). Use CSS easing/duration tokens as fallback for motion, not spring parity.
**Legacy easing/duration** remains valid for **transitions** (enter/exit/shared-axis) where the spec still references them; see the Motion table below.
## MD3 Compliance Audit
When invoked with `audit` as the argument (e.g., `/material-3 audit`), or when asked to audit/review MD3 compliance, analyze the target app or page and produce a compliance report.
### Audit Procedure
1. **Identify the target**: The user provides a URL (use browser tools to inspect), file paths (read source), or a running app.
2. **Inspect the following categories** and score each 0–10:
| Category | What to check |
|----------|--------------|
| **Color tokens** | **Web:** `--md-sys-color-*` / generated CSS. **Compose:** `MaterialTheme.colorScheme` roles (no arbitrary `Color(...)` for surfaces without reason). Proper tonal pairing (`onX` on `X`). Dark theme. **Flutter:** `ColorScheme` roles. |
| **Typography** | MD3 type scale: **Compose** `MaterialTheme.typography`; **web** typescale tokens; correct roles (Display, Headline, Title, Body, Label). |
| **Shape** | **Compose** `MaterialTheme.shapes` / component `Shape`; **web** `var(--md-sys-shape-*)`. Buttons: full; cards: medium; avoid magic numbers. |
| **Elevation** | Tonal elevation (`Surface` tonal/shadow as appropriate). **Web:** hover/focus where relevant. |
| **Components** | **Compose:** Material3 composables (`Button`, `Scaffold`, etc.). **Web:** `@material/web` or spec-aligned HTML/CSS. Correct variants. |
| **Layout** | Canonical layouts; **Compose** window size class / adaptive APIs; readable max width on large widths; foldable hinge avoidance. |
| **Navigation** | Bar / rail / drawer / drawers+**Compose** `NavHost` patterns per size class; predictive back where applicable. |
| **Motion** | **Compose** `MotionScheme` / expressive APIs when used; transitions may still use easing/duration. **Web:** CSS motion tokens fallback. |
| **Accessibility** | MD3 roles help, but **verify contrast**: UI components often need **3:1** for large text/borders and **4.5:1** for normal text (WCAG 2.x). TalkBack/semantics (Compose), focus order, touch targets (~48dp). **Web:** ARIA, keyboard. |
| **Theming** | **Compose:** `MaterialTheme` + light/dark/dynamic as designed. **Web:** CSS custom properties on `:root` or subtree. **Flutter:** `ThemeData` + `ColorScheme`. |
3. **Generate the report**:
```
# MD3 Compliance Audit Report
Target: [URL or file path]
Date: [date]
Overall Score: [X/100]
## Scores by Category
| Category | Score | Status |
|----------------|-------|--------|
| Color tokens | X/10 | [pass/warn/fail] |
| Typography | X/10 | [pass/warn/fail] |
| Shape | X/10 | [pass/warn/fail] |
| Elevation | X/10 | [pass/warn/fail] |
| Components | X/10 | [pass/warn/fail] |
| Layout | X/10 | [pass/warn/fail] |
| Navigation | X/10 | [pass/warn/fail] |
| Motion | X/10 | [pass/warn/fail] |
| Accessibility | X/10 | [pass/warn/fail] |
| Theming | X/10 | [pass/warn/fail] |
## Critical Issues
[List items scoring 0-3 with specific file:line references and fixes]
## Warnings
[List items scoring 4-6 with recommendations]
## Passing
[List items scoring 7-10 with notes on what's done well]
## Recommended Fixes (Priority Order)
1. [Most impactful fix first]
2. ...
```
### Audit Methods
**For a live URL** (browser or devtools):
- Inspect computed styles and CSS variables (`--md-sys-*`)
- Resize viewport or use responsive mode for breakpoints
- Capture screenshots at key widths if helpful
**For source code** (file paths provided):
- **Compose/Kotlin:** `.kt` files — `MaterialTheme`, composables, `Color(0x…)` abuse, hard-coded `Dp`, missing `Modifier.semantics` where needed
- **Flutter:** `.dart` — `ThemeData`, `ColorScheme`
- **Web:** HTML/JSX/Vue/Svelte; CSS/SCSS for tokens
- Check **web** imports for `@material/web` vs `@material/mdc-*` (MD2)
**Quick checks** (adapt paths to your stack):
```
# Web: hardcoded colors
grep -rn '#[0-9a-fA-F]\{3,8\}' --include='*.css' --include='*.scss'
# Compose: raw Color(...) audits (sample — tune for your codebase)
grep -rn 'Color(0x' --include='*.kt'
# MD2 on web
grep -rn '@material/mdc-' --include='*.js' --include='*.ts'
```
**Browser automation** (if your environment exposes MCP browser tools): navigate, snapshot DOM/CSS variables, resize for breakpoints — optional, not required.
### Scoring Guide
- **9-10**: Fully MD3 compliant, uses correct tokens and patterns
- **7-8**: Mostly compliant, minor issues (e.g., a few hardcoded values)
- **4-6**: Partially compliant, some MD3 patterns but significant gaps
- **1-3**: Major violations, mostly non-MD3 or MD2 patterns
- **0**: Not applicable or completely absent
Status thresholds: **pass** (7+), **warn** (4-6), **fail** (0-3)
## Reference Documents
- `references/color-system.md` — Color roles, tonal palettes, dynamic color, Compose + CSS mapping
- `references/typography-and-shape.md` — Type scale, shape corners, elevation, motion, Expressive notes
- `references/component-catalog.md` — Components: Compose + `@material/web` where applicable
- `references/navigation-patterns.md` — Navigation selection, Compose-first adaptive patterns
- `references/layout-and-responsive.md` — Breakpoints, canonical layouts, insets, foldables
- `references/theming-and-dynamic-color.md` — Theming: Compose first, then Flutter and web

View File

@@ -0,0 +1,358 @@
# MD3 Color System
Complete reference for Material Design 3's color system: roles, tonal palettes, dynamic color, and scheme generation.
## Color Roles
MD3 defines 29+ color roles organized into groups. **Jetpack Compose:** map to `MaterialTheme.colorScheme` (e.g. `primary`, `onPrimary`). **Web:** each role exists as a CSS custom property `--md-sys-color-{role-name}`.
### Accent Colors
Three accent groups (primary, secondary, tertiary) each have 4 roles:
| Role | CSS Token | Purpose |
|------|-----------|---------|
| Primary | `--md-sys-color-primary` | High-emphasis fills, text, icons against surface |
| On Primary | `--md-sys-color-on-primary` | Text and icons on primary |
| Primary Container | `--md-sys-color-primary-container` | Standout fill for key components (FAB, etc.) |
| On Primary Container | `--md-sys-color-on-primary-container` | Text and icons on primary-container |
| Secondary | `--md-sys-color-secondary` | Less prominent fills, text, icons |
| On Secondary | `--md-sys-color-on-secondary` | Text and icons on secondary |
| Secondary Container | `--md-sys-color-secondary-container` | Recessive components (tonal buttons) |
| On Secondary Container | `--md-sys-color-on-secondary-container` | Text and icons on secondary-container |
| Tertiary | `--md-sys-color-tertiary` | Complementary fills, text, icons |
| On Tertiary | `--md-sys-color-on-tertiary` | Text and icons on tertiary |
| Tertiary Container | `--md-sys-color-tertiary-container` | Complementary container fill |
| On Tertiary Container | `--md-sys-color-on-tertiary-container` | Text and icons on tertiary-container |
**Usage guidance:**
- **Primary**: Most prominent components — FABs, high-emphasis buttons, active states
- **Secondary**: Less prominent components — filter chips, tonal buttons, selection states
- **Tertiary**: Contrasting accents that balance primary/secondary — input fields, badges
### Error Colors
Static colors that don't change with dynamic color schemes:
| Role | CSS Token | Purpose |
|------|-----------|---------|
| Error | `--md-sys-color-error` | Attention-grabbing color for urgent elements |
| On Error | `--md-sys-color-on-error` | Text and icons on error |
| Error Container | `--md-sys-color-error-container` | Error container fill |
| On Error Container | `--md-sys-color-on-error-container` | Text and icons on error-container |
### Surface Colors
| Role | CSS Token | Purpose |
|------|-----------|---------|
| Surface | `--md-sys-color-surface` | Default background color |
| On Surface | `--md-sys-color-on-surface` | Text and icons on any surface |
| On Surface Variant | `--md-sys-color-on-surface-variant` | Lower-emphasis text/icons on surface |
| Surface Container Lowest | `--md-sys-color-surface-container-lowest` | Lowest-emphasis container |
| Surface Container Low | `--md-sys-color-surface-container-low` | Low-emphasis container |
| Surface Container | `--md-sys-color-surface-container` | Default container (navigation areas) |
| Surface Container High | `--md-sys-color-surface-container-high` | High-emphasis container |
| Surface Container Highest | `--md-sys-color-surface-container-highest` | Highest-emphasis container |
| Surface Dim | `--md-sys-color-surface-dim` | Dimmest surface in both themes |
| Surface Bright | `--md-sys-color-surface-bright` | Brightest surface in both themes |
**Surface container hierarchy**: Use `surface` for background, `surface-container` for navigation. The 5 container levels create visual hierarchy and nesting depth, especially useful for expanded layouts with multiple panes.
**Surface dim/bright**: Unlike regular surface (which flips from light to dark), dim and bright maintain their relative brightness in both themes. Use bright for areas that should always be the lightest, dim for areas that should always be the dimmest.
### Inverse Colors
For elements that contrast against the surrounding UI (e.g., snackbars):
| Role | CSS Token | Purpose |
|------|-----------|---------|
| Inverse Surface | `--md-sys-color-inverse-surface` | Background for contrasting elements |
| Inverse On Surface | `--md-sys-color-inverse-on-surface` | Text on inverse-surface |
| Inverse Primary | `--md-sys-color-inverse-primary` | Actionable text on inverse-surface |
### Outline Colors
| Role | CSS Token | Purpose |
|------|-----------|---------|
| Outline | `--md-sys-color-outline` | Important boundaries (text field borders, 3:1 contrast) |
| Outline Variant | `--md-sys-color-outline-variant` | Decorative elements (dividers, card borders) |
**Important**: Don't use `outline` for dividers — use `outline-variant`. Don't use `outline-variant` for interactive boundaries that need 3:1 contrast — use `outline`.
### Fixed Accent Colors (Add-on)
These maintain the same color in both light and dark themes (unlike regular container colors which change tone):
| Role | CSS Token |
|------|-----------|
| Primary Fixed | `--md-sys-color-primary-fixed` |
| Primary Fixed Dim | `--md-sys-color-primary-fixed-dim` |
| On Primary Fixed | `--md-sys-color-on-primary-fixed` |
| On Primary Fixed Variant | `--md-sys-color-on-primary-fixed-variant` |
| Secondary Fixed | `--md-sys-color-secondary-fixed` |
| Secondary Fixed Dim | `--md-sys-color-secondary-fixed-dim` |
| On Secondary Fixed | `--md-sys-color-on-secondary-fixed` |
| On Secondary Fixed Variant | `--md-sys-color-on-secondary-fixed-variant` |
| Tertiary Fixed | `--md-sys-color-tertiary-fixed` |
| Tertiary Fixed Dim | `--md-sys-color-tertiary-fixed-dim` |
| On Tertiary Fixed | `--md-sys-color-on-tertiary-fixed` |
| On Tertiary Fixed Variant | `--md-sys-color-on-tertiary-fixed-variant` |
**Caution**: Fixed colors don't adapt to theme, so they may cause contrast issues. Use regular accent roles for elements where contrast is critical.
## Tonal Palette System
MD3 generates colors from a **seed color** through the tonal palette system:
### How It Works
1. A **seed color** (hex value) is chosen
2. The seed generates **5 tonal palettes**: Primary, Secondary, Tertiary, Neutral, Neutral-Variant
3. Each palette uses tonal stops along **0–100** (commonly 16 key stops: 0, 10, 20, 25, 30, 35, 40, 50, 60, 70, 80, 90, 95, 98, 99, 100)
4. Color roles are mapped to specific tonal values depending on light or dark scheme
### Tonal Value Mapping (Light Scheme)
| Role | Tonal Palette | Tone |
|------|--------------|------|
| Primary | Primary | 40 |
| On Primary | Primary | 100 |
| Primary Container | Primary | 90 |
| On Primary Container | Primary | 10 |
| Surface | Neutral | 98 |
| On Surface | Neutral | 10 |
| Surface Container | Neutral | 94 |
| Surface Container Low | Neutral | 96 |
| Surface Container Lowest | Neutral | 100 |
| Surface Container High | Neutral | 92 |
| Surface Container Highest | Neutral | 90 |
| Outline | Neutral-Variant | 50 |
| Outline Variant | Neutral-Variant | 80 |
### Tonal Value Mapping (Dark Scheme)
| Role | Tonal Palette | Tone |
|------|--------------|------|
| Primary | Primary | 80 |
| On Primary | Primary | 20 |
| Primary Container | Primary | 30 |
| On Primary Container | Primary | 90 |
| Surface | Neutral | 6 |
| On Surface | Neutral | 90 |
| Surface Container | Neutral | 12 |
| Surface Container Low | Neutral | 10 |
| Surface Container Lowest | Neutral | 4 |
| Surface Container High | Neutral | 17 |
| Surface Container Highest | Neutral | 22 |
| Outline | Neutral-Variant | 60 |
| Outline Variant | Neutral-Variant | 30 |
## Color Pairing Rules
Colors must only be used in their intended pairs to ensure accessible contrast:
| Container/Fill | Text/Icon Color |
|---------------|----------------|
| `primary` | `on-primary` |
| `primary-container` | `on-primary-container` |
| `secondary` | `on-secondary` |
| `secondary-container` | `on-secondary-container` |
| `tertiary` | `on-tertiary` |
| `tertiary-container` | `on-tertiary-container` |
| `error` | `on-error` |
| `error-container` | `on-error-container` |
| `surface` | `on-surface` or `on-surface-variant` |
| `surface-container-*` | `on-surface` or `on-surface-variant` |
| `inverse-surface` | `inverse-on-surface` or `inverse-primary` |
**Never pair colors outside their intended pairs** — this breaks contrast guarantees, especially under dynamic color and high contrast modes.
## Dynamic Color
Dynamic color creates personalized color schemes from external sources:
### User-Generated (Wallpaper)
The OS extracts a seed color from the user's wallpaper and generates a scheme. **Android:** `dynamicLightColorScheme` / `dynamicDarkColorScheme` on **Android 12+ (API 31+)**. **Web:** there is **no** browser wallpaper dynamic-color API equivalent; you can derive a seed from **content** (e.g. images) with libraries, but that is app-specific, not system wallpaper theming.
### Content-Based
A seed color is extracted from in-app content (album art, book cover, etc.) to create a contextual scheme.
### Generating a Scheme with JavaScript
```javascript
import {
argbFromHex,
themeFromSourceColor,
applyTheme,
} from '@material/material-color-utilities';
// Generate a theme from a seed color
const theme = themeFromSourceColor(argbFromHex('#6750A4'));
// Apply to the document
applyTheme(theme, { target: document.body, dark: false });
```
### Manual CSS Generation from Seed
```javascript
import {
argbFromHex,
hexFromArgb,
SchemeContent,
Hct,
} from '@material/material-color-utilities';
function generateScheme(seedHex, isDark = false) {
const hct = Hct.fromInt(argbFromHex(seedHex));
const scheme = new SchemeContent(hct, isDark, 0.0); // 0.0 = standard contrast
return {
'--md-sys-color-primary': hexFromArgb(scheme.primary),
'--md-sys-color-on-primary': hexFromArgb(scheme.onPrimary),
'--md-sys-color-primary-container': hexFromArgb(scheme.primaryContainer),
'--md-sys-color-on-primary-container': hexFromArgb(scheme.onPrimaryContainer),
'--md-sys-color-secondary': hexFromArgb(scheme.secondary),
'--md-sys-color-on-secondary': hexFromArgb(scheme.onSecondary),
'--md-sys-color-secondary-container': hexFromArgb(scheme.secondaryContainer),
'--md-sys-color-on-secondary-container': hexFromArgb(scheme.onSecondaryContainer),
'--md-sys-color-tertiary': hexFromArgb(scheme.tertiary),
'--md-sys-color-on-tertiary': hexFromArgb(scheme.onTertiary),
'--md-sys-color-tertiary-container': hexFromArgb(scheme.tertiaryContainer),
'--md-sys-color-on-tertiary-container': hexFromArgb(scheme.onTertiaryContainer),
'--md-sys-color-error': hexFromArgb(scheme.error),
'--md-sys-color-on-error': hexFromArgb(scheme.onError),
'--md-sys-color-error-container': hexFromArgb(scheme.errorContainer),
'--md-sys-color-on-error-container': hexFromArgb(scheme.onErrorContainer),
'--md-sys-color-surface': hexFromArgb(scheme.surface),
'--md-sys-color-on-surface': hexFromArgb(scheme.onSurface),
'--md-sys-color-on-surface-variant': hexFromArgb(scheme.onSurfaceVariant),
'--md-sys-color-surface-container': hexFromArgb(scheme.surfaceContainer),
'--md-sys-color-surface-container-low': hexFromArgb(scheme.surfaceContainerLow),
'--md-sys-color-surface-container-lowest': hexFromArgb(scheme.surfaceContainerLowest),
'--md-sys-color-surface-container-high': hexFromArgb(scheme.surfaceContainerHigh),
'--md-sys-color-surface-container-highest': hexFromArgb(scheme.surfaceContainerHighest),
'--md-sys-color-outline': hexFromArgb(scheme.outline),
'--md-sys-color-outline-variant': hexFromArgb(scheme.outlineVariant),
'--md-sys-color-inverse-surface': hexFromArgb(scheme.inverseSurface),
'--md-sys-color-inverse-on-surface': hexFromArgb(scheme.inverseOnSurface),
'--md-sys-color-inverse-primary': hexFromArgb(scheme.inversePrimary),
};
}
// Apply to document
function applyScheme(seedHex, isDark = false) {
const tokens = generateScheme(seedHex, isDark);
const root = document.documentElement;
for (const [property, value] of Object.entries(tokens)) {
root.style.setProperty(property, value);
}
}
```
## Color Harmonization
When integrating custom brand colors that don't come from the seed, use harmonization to blend them into the tonal system:
```javascript
import { Blend } from '@material/material-color-utilities';
// Harmonize a custom color with the primary color
const harmonized = Blend.harmonize(customColorArgb, primaryColorArgb);
```
This shifts the custom color's hue slightly toward the scheme's primary, making it feel cohesive without losing its identity.
## User-Controlled Contrast (May 2025)
MD3 now supports 3 contrast levels:
- **Standard** (0.0): Default contrast
- **Medium** (0.5): Increased tonal distance between roles
- **High** (1.0): Maximum tonal distance for vision accessibility
```javascript
// Generate high contrast scheme
const scheme = new SchemeContent(hct, isDark, 1.0); // 1.0 = high contrast
```
The contrast parameter adjusts the tonal distance between paired roles, increasing legibility without changing the overall color feel.
## Baseline Color Scheme (Default Values)
The static baseline scheme for products not using dynamic color:
### Light Theme
```css
:root {
--md-sys-color-primary: #6750A4;
--md-sys-color-on-primary: #FFFFFF;
--md-sys-color-primary-container: #EADDFF;
--md-sys-color-on-primary-container: #21005D;
--md-sys-color-secondary: #625B71;
--md-sys-color-on-secondary: #FFFFFF;
--md-sys-color-secondary-container: #E8DEF8;
--md-sys-color-on-secondary-container: #1D192B;
--md-sys-color-tertiary: #7D5260;
--md-sys-color-on-tertiary: #FFFFFF;
--md-sys-color-tertiary-container: #FFD8E4;
--md-sys-color-on-tertiary-container: #31111D;
--md-sys-color-error: #B3261E;
--md-sys-color-on-error: #FFFFFF;
--md-sys-color-error-container: #F9DEDC;
--md-sys-color-on-error-container: #410E0B;
--md-sys-color-surface: #FEF7FF;
--md-sys-color-on-surface: #1D1B20;
--md-sys-color-on-surface-variant: #49454F;
--md-sys-color-surface-container-lowest: #FFFFFF;
--md-sys-color-surface-container-low: #F7F2FA;
--md-sys-color-surface-container: #F3EDF7;
--md-sys-color-surface-container-high: #ECE6F0;
--md-sys-color-surface-container-highest: #E6E0E9;
--md-sys-color-surface-dim: #DED8E1;
--md-sys-color-surface-bright: #FEF7FF;
--md-sys-color-outline: #79747E;
--md-sys-color-outline-variant: #CAC4D0;
--md-sys-color-inverse-surface: #322F35;
--md-sys-color-inverse-on-surface: #F5EFF7;
--md-sys-color-inverse-primary: #D0BCFF;
}
```
### Dark Theme
```css
@media (prefers-color-scheme: dark) {
:root {
--md-sys-color-primary: #D0BCFF;
--md-sys-color-on-primary: #381E72;
--md-sys-color-primary-container: #4F378B;
--md-sys-color-on-primary-container: #EADDFF;
--md-sys-color-secondary: #CCC2DC;
--md-sys-color-on-secondary: #332D41;
--md-sys-color-secondary-container: #4A4458;
--md-sys-color-on-secondary-container: #E8DEF8;
--md-sys-color-tertiary: #EFB8C8;
--md-sys-color-on-tertiary: #492532;
--md-sys-color-tertiary-container: #633B48;
--md-sys-color-on-tertiary-container: #FFD8E4;
--md-sys-color-error: #F2B8B5;
--md-sys-color-on-error: #601410;
--md-sys-color-error-container: #8C1D18;
--md-sys-color-on-error-container: #F9DEDC;
--md-sys-color-surface: #141218;
--md-sys-color-on-surface: #E6E0E9;
--md-sys-color-on-surface-variant: #CAC4D0;
--md-sys-color-surface-container-lowest: #0F0D13;
--md-sys-color-surface-container-low: #1D1B20;
--md-sys-color-surface-container: #211F26;
--md-sys-color-surface-container-high: #2B2930;
--md-sys-color-surface-container-highest: #36343B;
--md-sys-color-surface-dim: #141218;
--md-sys-color-surface-bright: #3B383E;
--md-sys-color-outline: #938F99;
--md-sys-color-outline-variant: #49454F;
--md-sys-color-inverse-surface: #E6E0E9;
--md-sys-color-inverse-on-surface: #322F35;
--md-sys-color-inverse-primary: #6750A4;
}
}
```

View File

@@ -0,0 +1,836 @@
# MD3 Component Catalog
Complete reference for Material Design 3 components. **Primary mappings:** Jetpack Compose (`androidx.compose.material3`) where most users ship UIs today; **web** uses `@material/web` element names and imports — [Material Web is maintenance-only](https://m3.material.io/develop/web).
## Google I/O 2026 Component Updates
Material's [I/O 2026 update](https://m3.material.io/blog/whats-new-at-io26) highlights refreshed expressive guidance for **lists**, **menus**, **search**, and **search app bars**, with Jetpack Compose as the primary implementation path. When implementing these in Android:
- Prefer current `androidx.compose.material3` components and verify expressive APIs against the active Material3 BOM.
- Expect expressive variants to include richer visual style, motion, and flexible configuration.
- Treat web implementations as spec-aligned approximations unless Material Web exposes an equivalent component; Material Web remains maintenance-only.
## Actions
### Buttons
MD3 has 5 button types ordered by emphasis: Filled > Filled Tonal > Elevated > Outlined > Text.
**General attributes** (shared by all button types):
| Attribute | Type | Description |
|-----------|------|-------------|
| `disabled` | boolean | Disables the button |
| `href` | string | Turns button into a link |
| `target` | string | Link target (`_blank`, etc.) |
| `trailing-icon` | boolean | Moves icon to trailing position |
| `type` | string | Form type: `button`, `submit`, `reset` |
#### Filled Button
**Element**: `md-filled-button` | **Import**: `@material/web/button/filled-button.js`
**Use when**: Primary action, highest emphasis.
```html
<md-filled-button>Get started</md-filled-button>
<md-filled-button href="/signup">
<md-icon slot="icon">arrow_forward</md-icon>
Sign up
</md-filled-button>
```
**Customize**: `--md-filled-button-container-color`, `--md-filled-button-label-text-color`, `--md-filled-button-container-shape`, `--md-filled-button-container-height`
#### Filled Tonal Button
**Element**: `md-filled-tonal-button` | **Import**: `@material/web/button/filled-tonal-button.js`
**Use when**: Medium emphasis, softer than filled. Secondary actions alongside a filled button.
```html
<md-filled-tonal-button>Save draft</md-filled-tonal-button>
```
**Customize**: `--md-filled-tonal-button-container-color`, `--md-filled-tonal-button-label-text-color`
#### Elevated Button
**Element**: `md-elevated-button` | **Import**: `@material/web/button/elevated-button.js`
**Use when**: Medium emphasis with shadow. Use on colored backgrounds where tonal button blends in.
```html
<md-elevated-button>Add to cart</md-elevated-button>
```
#### Outlined Button
**Element**: `md-outlined-button` | **Import**: `@material/web/button/outlined-button.js`
**Use when**: Medium emphasis, neutral. Good for secondary actions.
```html
<md-outlined-button>Cancel</md-outlined-button>
```
**Customize**: `--md-outlined-button-outline-color`, `--md-outlined-button-outline-width`
#### Text Button
**Element**: `md-text-button` | **Import**: `@material/web/button/text-button.js`
**Use when**: Lowest emphasis. Inline actions, dialog actions, less important options.
```html
<md-text-button>Learn more</md-text-button>
```
#### Button Sizes (Expressive)
Buttons now support 5 sizes: extra-small, small (default), medium, large, extra-large. Set via CSS:
```css
md-filled-button { --md-filled-button-container-height: 32px; } /* XS */
md-filled-button { --md-filled-button-container-height: 40px; } /* S (default) */
md-filled-button { --md-filled-button-container-height: 48px; } /* M */
md-filled-button { --md-filled-button-container-height: 56px; } /* L */
md-filled-button { --md-filled-button-container-height: 64px; } /* XL */
```
**A11y**: Buttons have built-in button role. Use `aria-label` when using icon-only buttons. Minimum touch target 48x48dp.
### Button Group
**Element**: `md-button-group` | **Import**: `@material/web/button/button-group.js`
**Use when**: Grouping related actions together with connected visual treatment.
```html
<md-button-group>
<md-outlined-button>Day</md-outlined-button>
<md-outlined-button>Week</md-outlined-button>
<md-outlined-button>Month</md-outlined-button>
</md-button-group>
```
### FAB (Floating Action Button)
**Element**: `md-fab` | **Import**: `@material/web/fab/fab.js`
**Use when**: The single most important action on a screen.
| Attribute | Type | Description |
|-----------|------|-------------|
| `size` | string | `small`, `medium` (default), `large` |
| `variant` | string | `surface`, `primary`, `secondary`, `tertiary` |
| `label` | string | Text label (for extended FAB) |
```html
<md-fab aria-label="Create new">
<md-icon slot="icon">add</md-icon>
</md-fab>
<md-fab size="small" variant="tertiary" aria-label="Edit">
<md-icon slot="icon">edit</md-icon>
</md-fab>
```
**Customize**: `--md-fab-container-color`, `--md-fab-container-shape`, `--md-fab-icon-color`
**A11y**: Always provide `aria-label` since FABs are icon-only.
### Extended FAB
**Element**: `md-extended-fab` | **Import**: `@material/web/fab/extended-fab.js`
**Use when**: Primary action with explanatory text.
```html
<md-extended-fab label="New message">
<md-icon slot="icon">edit</md-icon>
</md-extended-fab>
```
### Icon Button
**Element**: `md-icon-button` | **Import**: `@material/web/iconbutton/icon-button.js`
4 variants with separate elements:
| Variant | Element | Import |
|---------|---------|--------|
| Standard | `md-icon-button` | `@material/web/iconbutton/icon-button.js` |
| Filled | `md-filled-icon-button` | `@material/web/iconbutton/filled-icon-button.js` |
| Filled Tonal | `md-filled-tonal-icon-button` | `@material/web/iconbutton/filled-tonal-icon-button.js` |
| Outlined | `md-outlined-icon-button` | `@material/web/iconbutton/outlined-icon-button.js` |
| Attribute | Type | Description |
|-----------|------|-------------|
| `toggle` | boolean | Enables toggle behavior |
| `selected` | boolean | Selected state (when toggle) |
```html
<md-icon-button aria-label="Settings">
<md-icon>settings</md-icon>
</md-icon-button>
<!-- Toggle icon button (like/unlike) -->
<md-icon-button toggle aria-label="Favorite">
<md-icon>favorite_border</md-icon>
<md-icon slot="selected">favorite</md-icon>
</md-icon-button>
```
**A11y**: Always provide `aria-label`. Toggle buttons should have descriptive labels for both states.
### Segmented Buttons
**No @material/web element yet.** Implement with standard HTML + MD3 tokens:
```html
<div class="md3-segmented-buttons" role="group" aria-label="View options">
<button class="md3-segmented-button md3-segmented-button--selected" aria-pressed="true">
<md-icon>view_list</md-icon> List
</button>
<button class="md3-segmented-button" aria-pressed="false">
<md-icon>grid_view</md-icon> Grid
</button>
</div>
```
```css
.md3-segmented-buttons {
display: flex;
border: 1px solid var(--md-sys-color-outline);
border-radius: var(--md-sys-shape-corner-full);
overflow: hidden;
}
.md3-segmented-button {
flex: 1;
padding: 10px 16px;
border: none;
background: transparent;
color: var(--md-sys-color-on-surface);
cursor: pointer;
font: var(--md-sys-typescale-label-large);
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
}
.md3-segmented-button--selected {
background: var(--md-sys-color-secondary-container);
color: var(--md-sys-color-on-secondary-container);
}
```
## Communication
### Badge
**No @material/web element yet.** Implement with CSS:
```html
<div class="md3-badge-container">
<md-icon>notifications</md-icon>
<span class="md3-badge md3-badge--large">3</span>
</div>
```
```css
.md3-badge-container { position: relative; display: inline-flex; }
.md3-badge {
position: absolute;
top: -4px;
right: -4px;
background: var(--md-sys-color-error);
color: var(--md-sys-color-on-error);
border-radius: var(--md-sys-shape-corner-full);
font: var(--md-sys-typescale-label-small);
}
.md3-badge--small { width: 6px; height: 6px; padding: 0; } /* dot only */
.md3-badge--large { min-width: 16px; height: 16px; padding: 0 4px; text-align: center; }
```
### Progress Indicator
**Elements**: `md-linear-progress`, `md-circular-progress`
**Import**: `@material/web/progress/linear-progress.js`, `@material/web/progress/circular-progress.js`
| Attribute | Type | Description |
|-----------|------|-------------|
| `value` | number | Current progress (0–1) |
| `max` | number | Maximum value (default 1) |
| `indeterminate` | boolean | Shows indeterminate animation |
| `four-color` | boolean | Four-color indeterminate variant |
```html
<!-- Determinate -->
<md-linear-progress value="0.6"></md-linear-progress>
<md-circular-progress value="0.75"></md-circular-progress>
<!-- Indeterminate -->
<md-linear-progress indeterminate></md-linear-progress>
<md-circular-progress indeterminate></md-circular-progress>
```
**Customize**: `--md-linear-progress-active-indicator-color`, `--md-circular-progress-active-indicator-color`
**A11y**: Has built-in `progressbar` role. Add `aria-label` for context (e.g., "Loading messages").
### Snackbar
**No @material/web element yet.** Implement with standard HTML:
```html
<div class="md3-snackbar" role="status" aria-live="polite">
<span class="md3-snackbar__text">Message sent</span>
<md-text-button class="md3-snackbar__action">Undo</md-text-button>
<md-icon-button class="md3-snackbar__close" aria-label="Dismiss">
<md-icon>close</md-icon>
</md-icon-button>
</div>
```
```css
.md3-snackbar {
background: var(--md-sys-color-inverse-surface);
color: var(--md-sys-color-inverse-on-surface);
border-radius: var(--md-sys-shape-corner-extra-small);
padding: 12px 16px;
display: flex;
align-items: center;
gap: 8px;
min-height: 48px;
max-width: 560px;
}
```
### Tooltip
**No @material/web element yet.**
Two types:
- **Plain**: Short text label, appears on hover/focus. Use for icon buttons and truncated text.
- **Rich**: Multi-line with optional actions. Use for complex explanations.
## Containment
### Card
**No @material/web element yet.** Three variants:
| Variant | Appearance | Elevation |
|---------|-----------|-----------|
| Filled | Surface-container-highest fill, no border | Level 0 |
| Outlined | Surface fill, outline-variant border | Level 0 |
| Elevated | Surface-container-low fill, shadow | Level 1 |
```html
<!-- Outlined card -->
<div class="md3-card md3-card--outlined">
<div class="md3-card__content">
<h3 style="font: var(--md-sys-typescale-title-medium)">Title</h3>
<p style="font: var(--md-sys-typescale-body-medium); color: var(--md-sys-color-on-surface-variant)">
Supporting text
</p>
</div>
<div class="md3-card__actions">
<md-filled-tonal-button>Action</md-filled-tonal-button>
</div>
</div>
<!-- Filled card -->
<div class="md3-card md3-card--filled">...</div>
<!-- Elevated card -->
<div class="md3-card md3-card--elevated">...</div>
```
```css
.md3-card {
border-radius: var(--md-sys-shape-corner-medium, 12px);
overflow: hidden;
}
.md3-card--outlined {
background: var(--md-sys-color-surface);
border: 1px solid var(--md-sys-color-outline-variant);
}
.md3-card--filled {
background: var(--md-sys-color-surface-container-highest);
}
.md3-card--elevated {
background: var(--md-sys-color-surface-container-low);
box-shadow: 0 1px 2px rgba(0,0,0,0.3), 0 1px 3px 1px rgba(0,0,0,0.15);
}
.md3-card__content { padding: 16px; }
.md3-card__actions { padding: 16px; display: flex; gap: 8px; justify-content: flex-end; }
```
### Dialog
**Element**: `md-dialog` | **Import**: `@material/web/dialog/dialog.js`
| Attribute | Type | Description |
|-----------|------|-------------|
| `open` | boolean | Shows the dialog |
| `type` | string | `alert` (default) |
```html
<md-dialog id="confirm-dialog">
<div slot="headline">Confirm action</div>
<form slot="content" method="dialog">
Are you sure you want to proceed?
</form>
<div slot="actions">
<md-text-button form="confirm-dialog" value="cancel">Cancel</md-text-button>
<md-filled-tonal-button form="confirm-dialog" value="confirm">Confirm</md-filled-tonal-button>
</div>
</md-dialog>
```
**A11y**: Dialog traps focus automatically. Use `slot="headline"` for accessible title.
### Bottom Sheet
**No @material/web element yet.** Two variants: Standard (persistent, coexists with content) and Modal (blocks interaction, has scrim).
### Side Sheet
**No @material/web element yet.** Two variants: Standard (docked alongside content) and Modal (overlays content with scrim).
### Divider
**Element**: `md-divider` | **Import**: `@material/web/divider/divider.js`
| Attribute | Type | Description |
|-----------|------|-------------|
| `inset` | boolean | Adds inset on both sides |
| `inset-start` | boolean | Adds inset on start side |
| `inset-end` | boolean | Adds inset on end side |
```html
<md-divider></md-divider>
<md-divider inset></md-divider>
```
### Carousel
**No @material/web element yet.** Three configurations:
- **Multi-browse**: Multiple items visible, scrollable
- **Uncontained**: Items extend beyond viewport edges
- **Hero**: One large featured item with smaller previews
## Input
### Checkbox
**Element**: `md-checkbox` | **Import**: `@material/web/checkbox/checkbox.js`
| Attribute | Type | Description |
|-----------|------|-------------|
| `checked` | boolean | Checked state |
| `indeterminate` | boolean | Indeterminate state |
| `disabled` | boolean | Disabled state |
| `required` | boolean | Required for form validation |
```html
<label>
<md-checkbox></md-checkbox>
Accept terms
</label>
<label>
<md-checkbox checked></md-checkbox>
Remember me
</label>
```
**A11y**: Wrap in `<label>` or use `aria-label`. Checkbox has built-in checkbox role.
### Chips
**Elements**: `md-chip-set`, `md-assist-chip`, `md-filter-chip`, `md-input-chip`, `md-suggestion-chip`
**Import**: `@material/web/chips/*.js`
| Variant | Element | Use |
|---------|---------|-----|
| Assist | `md-assist-chip` | Smart suggestions, shortcuts |
| Filter | `md-filter-chip` | Filtering content, multi-select |
| Input | `md-input-chip` | User input tokens (email recipients) |
| Suggestion | `md-suggestion-chip` | Suggested responses, queries |
```html
<md-chip-set>
<md-filter-chip label="Vegetarian" selected></md-filter-chip>
<md-filter-chip label="Vegan"></md-filter-chip>
<md-filter-chip label="Gluten-free"></md-filter-chip>
</md-chip-set>
<md-chip-set>
<md-input-chip label="user@example.com" removable></md-input-chip>
</md-chip-set>
```
### Menu
**Elements**: `md-menu`, `md-menu-item`, `md-sub-menu`
**Import**: `@material/web/menu/menu.js`, `@material/web/menu/menu-item.js`
**I/O 2026 note:** Expressive menus have updated Material guidance for more flexible, vibrant configurations. In Jetpack Compose, prefer current Material3 menu APIs and expressive variants when available in your BOM. On web, use `md-menu` / `md-menu-item` for token-backed menus, or build custom spec-aligned variants when expressive behavior is required.
| Attribute (menu) | Type | Description |
|-----------------|------|-------------|
| `anchor` | string | ID of the anchor element |
| `open` | boolean | Shows the menu |
| `positioning` | string | `absolute`, `fixed`, `popover` |
```html
<span style="position: relative;">
<md-filled-button id="menu-trigger">Options</md-filled-button>
<md-menu id="options-menu" anchor="menu-trigger">
<md-menu-item>
<div slot="headline">Edit</div>
<md-icon slot="start">edit</md-icon>
</md-menu-item>
<md-menu-item>
<div slot="headline">Delete</div>
<md-icon slot="start">delete</md-icon>
</md-menu-item>
</md-menu>
</span>
<script>
document.getElementById('menu-trigger').addEventListener('click', () => {
document.getElementById('options-menu').open = !document.getElementById('options-menu').open;
});
</script>
```
### Radio Button
**Element**: `md-radio` | **Import**: `@material/web/radio/radio.js`
```html
<div role="radiogroup" aria-label="Size">
<label><md-radio name="size" value="s"></md-radio> Small</label>
<label><md-radio name="size" value="m" checked></md-radio> Medium</label>
<label><md-radio name="size" value="l"></md-radio> Large</label>
</div>
```
**A11y**: Group radios in a container with `role="radiogroup"` and `aria-label`.
### Slider
**Element**: `md-slider` | **Import**: `@material/web/slider/slider.js`
| Attribute | Type | Description |
|-----------|------|-------------|
| `value` | number | Current value |
| `min` | number | Minimum value |
| `max` | number | Maximum value |
| `step` | number | Step increment (makes discrete) |
| `labeled` | boolean | Shows value label |
| `range` | boolean | Enables range selection |
| `value-start` | number | Start value (range mode) |
| `value-end` | number | End value (range mode) |
```html
<!-- Continuous -->
<md-slider value="50" min="0" max="100" aria-label="Volume"></md-slider>
<!-- Discrete with label -->
<md-slider value="3" min="1" max="10" step="1" labeled aria-label="Rating"></md-slider>
<!-- Range -->
<md-slider range value-start="20" value-end="80" min="0" max="100" aria-label="Price range"></md-slider>
```
### Switch
**Element**: `md-switch` | **Import**: `@material/web/switch/switch.js`
| Attribute | Type | Description |
|-----------|------|-------------|
| `selected` | boolean | On state |
| `icons` | boolean | Show on/off icons |
| `disabled` | boolean | Disabled state |
```html
<label>
<md-switch></md-switch>
Dark mode
</label>
<label>
<md-switch selected icons></md-switch>
Notifications
</label>
```
**Customize**: `--md-switch-selected-handle-color`, `--md-switch-selected-track-color`
### Text Field
**Elements**: `md-filled-text-field`, `md-outlined-text-field`
**Import**: `@material/web/textfield/filled-text-field.js`, `@material/web/textfield/outlined-text-field.js`
| Attribute | Type | Description |
|-----------|------|-------------|
| `label` | string | Label text |
| `value` | string | Current value |
| `type` | string | Input type (text, email, password, number, textarea, etc.) |
| `placeholder` | string | Placeholder text |
| `required` | boolean | Required validation |
| `disabled` | boolean | Disabled state |
| `error` | boolean | Error state |
| `error-text` | string | Error message |
| `supporting-text` | string | Helper text |
| `prefix-text` | string | Prefix text |
| `suffix-text` | string | Suffix text |
| `max-length` | number | Character limit (shows counter) |
| `rows` | number | Rows (for textarea) |
```html
<!-- Outlined (recommended for most uses) -->
<md-outlined-text-field
label="Email"
type="email"
required
supporting-text="We'll never share your email">
</md-outlined-text-field>
<!-- Filled -->
<md-filled-text-field
label="Search"
type="text"
placeholder="Type to search...">
<md-icon slot="leading-icon">search</md-icon>
</md-filled-text-field>
<!-- With error -->
<md-outlined-text-field
label="Password"
type="password"
error
error-text="Password must be at least 8 characters"
min-length="8">
</md-outlined-text-field>
<!-- Textarea -->
<md-outlined-text-field
label="Message"
type="textarea"
rows="4"
max-length="500">
</md-outlined-text-field>
```
**Customize**: `--md-outlined-text-field-container-shape`, `--md-outlined-text-field-focus-outline-color`, `--md-filled-text-field-container-color`
#### Jetpack Compose
Use **`OutlinedTextField`** / **`TextField`** from **`androidx.compose.material3`**. Prefer **state-based** APIs (`TextFieldState`, `rememberTextFieldState()`) when targeting current Material3 releases — see the [package overview](https://developer.android.com/reference/kotlin/androidx/compose/material3/package-summary). Map labels, supporting text, and error state to MD3 roles (`MaterialTheme.colorScheme`, `TextFieldDefaults`).
```kotlin
// Illustrative — API names vary slightly by Material3 version
val state = rememberTextFieldState("")
OutlinedTextField(
state = state,
label = { Text("Email") },
supportingText = { if (isError) Text("Invalid email") },
isError = isError,
modifier = Modifier.fillMaxWidth()
)
```
### Date Picker
**No @material/web element yet.** Three configurations:
- **Docked**: Inline calendar attached to input
- **Modal**: Full dialog for date selection
- **Range**: Select a date range
### Time Picker
**No @material/web element yet.** Two configurations:
- **Docked**: Inline time input
- **Modal**: Clock dial in dialog
## Navigation
### App Bar (Top)
**No @material/web element yet.** Four variants:
| Variant | Height | Title position | Scroll behavior |
|---------|--------|---------------|----------------|
| Center-aligned | 64dp | Center | Elevate on scroll |
| Small | 64dp | Left | Elevate on scroll |
| Medium | 112dp | Left, bottom | Collapse to small on scroll |
| Large | 152dp | Left, bottom | Collapse to small on scroll |
**Jetpack Compose:** `TopAppBar`, `CenterAlignedTopAppBar`, `MediumTopAppBar`, `LargeTopAppBar`, and expressive variants (e.g. large flexible) may require **`@OptIn(ExperimentalMaterial3ExpressiveApi::class)`** depending on BOM — check your `material3` version.
```html
<header class="md3-top-app-bar md3-top-app-bar--small">
<md-icon-button aria-label="Menu"><md-icon>menu</md-icon></md-icon-button>
<span class="md3-top-app-bar__title" style="font: var(--md-sys-typescale-title-large)">
Page Title
</span>
<md-icon-button aria-label="Search"><md-icon>search</md-icon></md-icon-button>
<md-icon-button aria-label="More"><md-icon>more_vert</md-icon></md-icon-button>
</header>
```
```css
.md3-top-app-bar {
height: 64px;
padding: 0 4px;
display: flex;
align-items: center;
gap: 4px;
background: var(--md-sys-color-surface);
color: var(--md-sys-color-on-surface);
}
.md3-top-app-bar__title { flex: 1; padding: 0 12px; }
/* Scrolled state */
.md3-top-app-bar--scrolled { background: var(--md-sys-color-surface-container); }
```
### Navigation Bar
**Element**: `md-navigation-bar` | **Import**: `@material/web/navigation/navigation-bar.js`
**Use when**: 3–5 primary destinations, mobile/compact screens, persistent.
```html
<md-navigation-bar>
<md-navigation-tab label="Home" active>
<md-icon slot="active-icon">home</md-icon>
<md-icon slot="inactive-icon">home</md-icon>
</md-navigation-tab>
<md-navigation-tab label="Explore">
<md-icon slot="active-icon">explore</md-icon>
<md-icon slot="inactive-icon">explore</md-icon>
</md-navigation-tab>
<md-navigation-tab label="Profile">
<md-icon slot="active-icon">person</md-icon>
<md-icon slot="inactive-icon">person</md-icon>
</md-navigation-tab>
</md-navigation-bar>
```
### Navigation Drawer
**Element**: `md-navigation-drawer` | **Import**: `@material/web/navigation/navigation-drawer.js`
**Use when**: Many destinations, larger screens, can be modal or persistent.
| Attribute | Type | Description |
|-----------|------|-------------|
| `opened` | boolean | Open state |
| `type` | string | `standard` or `modal` |
```html
<md-navigation-drawer opened>
<div slot="headline">Mail</div>
<md-list>
<md-list-item type="button" active>
<md-icon slot="start">inbox</md-icon>
Inbox
</md-list-item>
<md-list-item type="button">
<md-icon slot="start">send</md-icon>
Sent
</md-list-item>
</md-list>
</md-navigation-drawer>
```
### Navigation Rail
**No @material/web element yet.** Use when: 3–7 destinations, medium screens (600–839dp), persistent side navigation.
```html
<nav class="md3-nav-rail" aria-label="Main">
<md-fab size="small" variant="tertiary" aria-label="Compose">
<md-icon slot="icon">edit</md-icon>
</md-fab>
<div class="md3-nav-rail__items">
<a href="/" class="md3-nav-rail__item md3-nav-rail__item--active" aria-current="page">
<md-icon>home</md-icon>
<span>Home</span>
</a>
<a href="/search" class="md3-nav-rail__item">
<md-icon>search</md-icon>
<span>Search</span>
</a>
</div>
</nav>
```
```css
.md3-nav-rail {
width: 80px;
display: flex;
flex-direction: column;
align-items: center;
padding: 12px 0;
gap: 12px;
background: var(--md-sys-color-surface);
}
.md3-nav-rail__items { display: flex; flex-direction: column; gap: 12px; }
.md3-nav-rail__item {
display: flex;
flex-direction: column;
align-items: center;
gap: 4px;
padding: 4px 0;
text-decoration: none;
color: var(--md-sys-color-on-surface-variant);
font: var(--md-sys-typescale-label-medium);
}
.md3-nav-rail__item--active { color: var(--md-sys-color-on-surface); }
```
### Search
**No @material/web element yet.** Two patterns:
- **Search bar**: Persistent search field in top app bar area
- **Search view**: Expandable search overlay with suggestions
**I/O 2026 note:** Expressive search and search app bar guidance adds a refreshed visual style, motion, and more flexible trailing icon behavior. In Jetpack Compose, use the current Material3 search APIs and expressive app bar variants where available. On web, implement search as a custom component using MD3 shape, color, spacing, and motion tokens.
### Tabs
**Elements**: `md-tabs`, `md-primary-tab`, `md-secondary-tab`
**Import**: `@material/web/tabs/tabs.js`, `@material/web/tabs/primary-tab.js`, `@material/web/tabs/secondary-tab.js`
| Variant | Element | Use |
|---------|---------|-----|
| Primary | `md-primary-tab` | Top-level navigation within a page |
| Secondary | `md-secondary-tab` | Sub-sections within primary tabs |
```html
<md-tabs>
<md-primary-tab active>
<md-icon slot="icon">flight</md-icon>
Flights
</md-primary-tab>
<md-primary-tab>
<md-icon slot="icon">hotel</md-icon>
Hotels
</md-primary-tab>
<md-primary-tab>
<md-icon slot="icon">explore</md-icon>
Explore
</md-primary-tab>
</md-tabs>
```
**A11y**: Tab set has built-in tablist role. Connect tabs to panels with `aria-controls`.
### Toolbar
**No @material/web element yet.** Displays frequently used actions relevant to current page context. Typically placed below top app bar or in contextual positions.
## Data Display
### List
**Elements**: `md-list`, `md-list-item`
**Import**: `@material/web/list/list.js`, `@material/web/list/list-item.js`
**I/O 2026 note:** Expressive lists add more vibrant styles and flexible item configurations. In Compose, prefer Material3 list patterns and keep spacing, leading/trailing content, supporting text, and dividers token-driven. On web, `md-list` is useful for standard lists; custom CSS may be needed for expressive list treatments.
| Attribute (list-item) | Type | Description |
|----------------------|------|-------------|
| `type` | string | `text` (default), `button`, `link` |
| `href` | string | URL (when type="link") |
| `disabled` | boolean | Disabled state |
```html
<md-list>
<!-- One-line -->
<md-list-item>Single line item</md-list-item>
<!-- Two-line with icon -->
<md-list-item>
<md-icon slot="start">person</md-icon>
<div slot="headline">Jane Smith</div>
<div slot="supporting-text">Senior Developer</div>
</md-list-item>
<!-- Three-line -->
<md-list-item>
<md-icon slot="start">mail</md-icon>
<div slot="headline">Meeting notes</div>
<div slot="supporting-text">Please review the attached notes from today's standup meeting and provide feedback.</div>
<div slot="trailing-supporting-text">3 min ago</div>
</md-list-item>
<md-divider></md-divider>
<!-- Clickable item -->
<md-list-item type="button" onclick="handleClick()">
<md-icon slot="start">settings</md-icon>
<div slot="headline">Settings</div>
<md-icon slot="end">chevron_right</md-icon>
</md-list-item>
</md-list>
```
**Slots**: `start` (leading element), `end` (trailing element), `headline` (primary text), `supporting-text` (secondary text), `trailing-supporting-text` (trailing metadata), `overline` (above headline)

View File

@@ -0,0 +1,733 @@
# MD3 Layout and Responsive Design
Reference for Material Design 3's layout system: breakpoints, canonical layouts, and responsive implementation.
## Jetpack Compose and Android
The **breakpoint table** below is a **design** reference. In **Jetpack Compose**, prefer **`calculateWindowSizeClass`** (`androidx.compose.material3:material3-window-size-class`) and/or **`androidx.compose.material3.adaptive`** APIs (e.g. `currentWindowAdaptiveInfo`, list-detail scaffolds) instead of hand-rolling raw `BoxWithConstraints` width checks everywhere.
**Edge-to-edge:** Use **`enableEdgeToEdge()`** on your `Activity` (AndroidX) when you draw behind the system bars. Apply **`WindowInsets`** (`Modifier.statusBarsPadding()`, `navigationBarsPadding()`, **`imePadding()`**, `displayCutoutPadding()`, etc.) and **`Scaffold`** `contentWindowInsets` so content and **IME** behave correctly.
**Foldables:** Use **`WindowInfoTracker`**, **`FoldingFeature`**, or Jetpack WindowManager APIs — see the foldable section below; verify APIs against your dependency versions.
---
## Google I/O 2026: Expressive Layout
Material's [I/O 2026 update](https://m3.material.io/blog/whats-new-at-io26) introduced broader expressive/adaptive layout guidance:
- **Expressive layout scaffold**: Design screens to adapt across mobile, desktop, foldables, watches, XR, and other spatial form factors. In Compose, prefer Material3 adaptive scaffolds and window size classes over hard-coded phone/tablet branches.
- **8dp spacing system**: Treat spacing as tokens. Use an 8dp scale for margins, padding, gaps, and component spacing so density and device-class changes can be applied consistently.
- **Watch guidance**: Use physics-based motion, arc text styles, and edge-hugging containers. Avoid shrinking phone layouts onto a round or compact wearable screen.
- **XR guidance**: Use spatial panels and depth-based elevation. Avoid treating XR as only a larger desktop canvas; account for depth, comfort, and panel placement.
### Spacing Token Pattern
Define spacing once, then map it to context:
```kotlin
object MdSpacing {
val xxs = 4.dp
val xs = 8.dp
val sm = 16.dp
val md = 24.dp
val lg = 32.dp
val xl = 48.dp
}
```
Use spacing tokens for:
- Screen margins
- Pane gaps
- List item spacing
- Card internal padding
- Component groups and toolbars
Do not scatter raw `Dp` literals throughout reusable UI. Keep one-off values local only when they are truly component-specific.
---
## Window Size Classes
MD3 defines 5 breakpoint classes:
| Class | Width Range | Typical Devices | Columns |
|-------|-----------|----------------|---------|
| Compact | < 600dp | Phone portrait | 4 |
| Medium | 600–839dp | Tablet portrait, foldable | 8 |
| Expanded | 840–1199dp | Tablet landscape, small desktop | 12 |
| Large | 1200–1599dp | Desktop | 12 |
| Extra-large | 1600dp+ | Ultra-wide, large desktop | 12 |
### CSS Media Queries (web)
Use these for **CSS layouts**. **Compose** apps should use window size classes / adaptive APIs rather than duplicating this logic only in CSS.
```css
/* Compact (default — mobile-first) */
/* No media query needed, this is the base */
/* Medium */
@media (min-width: 600px) { }
/* Expanded */
@media (min-width: 840px) { }
/* Large */
@media (min-width: 1200px) { }
/* Extra-large */
@media (min-width: 1600px) { }
```
### dp to px Conversion
On the web, 1dp ≈ 1px at standard density. The breakpoint values translate directly to CSS pixels.
## Layout Anatomy
### Key Terms
- **Window**: The visible area of the app
- **Pane**: A layout container within the window. A pane is fixed, flexible, floating, or semi-permanent
- **Column**: A vertical content block within a pane
- **Margin**: Space between screen edge and content
- **Gutter**: Space between columns
- **Spacer**: Space between panes (in multi-pane layouts)
### Margin and Gutter Values
| Window Size | Margins | Gutters |
|-------------|---------|---------|
| Compact | 16dp | 8dp |
| Medium | 24dp | 16dp |
| Expanded | 24dp | 16dp |
| Large | 24dp | 24dp |
| Extra-large | 24dp | 24dp |
## Canonical Layouts
MD3 defines 3 canonical layouts as starting points. Always begin from one of these rather than from a raw grid.
### Feed Layout
**Use when**: Displaying a large collection of browsable items (social feed, news, product grid).
```
Compact: Single column of cards
Medium: 2-column grid
Expanded: 3-column grid
Large: 4-column grid + optional side panel
```
```html
<div class="md3-feed">
<div class="md3-feed__item">
<!-- Card content -->
</div>
<div class="md3-feed__item">
<!-- Card content -->
</div>
<!-- More items -->
</div>
```
```css
.md3-feed {
display: grid;
gap: 8px;
padding: 16px;
grid-template-columns: 1fr; /* Compact: 1 column */
}
@media (min-width: 600px) {
.md3-feed {
grid-template-columns: repeat(2, 1fr);
gap: 16px;
padding: 24px;
}
}
@media (min-width: 840px) {
.md3-feed {
grid-template-columns: repeat(3, 1fr);
}
}
@media (min-width: 1200px) {
.md3-feed {
grid-template-columns: repeat(4, 1fr);
gap: 24px;
}
}
```
### List-Detail Layout
**Use when**: Browsing a list of items where each has detailed content (email, file browser, contacts).
```
Compact: List view OR detail view (navigate between them)
Medium: Side-by-side list (1/3) + detail (2/3)
Expanded: Side-by-side with wider detail pane
```
```html
<div class="md3-list-detail">
<aside class="md3-list-detail__list">
<md-list>
<md-list-item type="button" class="active">
<div slot="headline">Item 1</div>
<div slot="supporting-text">Description</div>
</md-list-item>
<md-list-item type="button">
<div slot="headline">Item 2</div>
<div slot="supporting-text">Description</div>
</md-list-item>
</md-list>
</aside>
<main class="md3-list-detail__detail">
<h2>Item 1 Detail</h2>
<p>Full content here...</p>
</main>
</div>
```
```css
.md3-list-detail {
display: flex;
flex-direction: column;
min-height: 100%;
}
.md3-list-detail__list {
background: var(--md-sys-color-surface-container);
border-radius: var(--md-sys-shape-corner-large);
overflow: auto;
}
.md3-list-detail__detail {
flex: 1;
padding: 24px;
}
/* Compact: show one at a time */
@media (max-width: 599px) {
.md3-list-detail__detail { display: none; }
.md3-list-detail--detail-active .md3-list-detail__list { display: none; }
.md3-list-detail--detail-active .md3-list-detail__detail { display: block; }
}
/* Medium+: side by side */
@media (min-width: 600px) {
.md3-list-detail {
flex-direction: row;
gap: 24px;
padding: 24px;
}
.md3-list-detail__list {
width: 360px;
flex-shrink: 0;
}
}
/* Expanded: wider detail */
@media (min-width: 840px) {
.md3-list-detail__list {
width: 400px;
}
}
```
### Drag Handle for Resizable Panes
In list-detail and supporting pane layouts, users can resize panes with a drag handle:
```html
<div class="md3-list-detail">
<aside class="md3-list-detail__list">...</aside>
<div class="md3-drag-handle" role="separator" aria-orientation="vertical" tabindex="0"></div>
<main class="md3-list-detail__detail">...</main>
</div>
```
```css
.md3-drag-handle {
width: 4px;
cursor: col-resize;
background: transparent;
position: relative;
}
.md3-drag-handle::after {
content: '';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 4px;
height: 24px;
background: var(--md-sys-color-outline);
border-radius: 2px;
}
```
### Supporting Pane Layout
**Use when**: Primary content needs supplementary information (document + properties panel, video + comments).
```
Compact: Stacked — primary on top, supporting below (or bottom sheet)
Medium: Side-by-side (2/3 primary + 1/3 supporting)
Expanded: Same but with more space
```
```html
<div class="md3-supporting-pane">
<main class="md3-supporting-pane__primary">
<!-- Primary content (2/3) -->
</main>
<aside class="md3-supporting-pane__secondary">
<!-- Supporting content (1/3) -->
</aside>
</div>
```
```css
.md3-supporting-pane {
display: flex;
flex-direction: column;
gap: 16px;
padding: 16px;
}
/* Medium+: side by side */
@media (min-width: 600px) {
.md3-supporting-pane {
flex-direction: row;
gap: 24px;
padding: 24px;
}
.md3-supporting-pane__primary { flex: 2; }
.md3-supporting-pane__secondary { flex: 1; }
}
```
## CSS Container Queries
For component-level responsive behavior (independent of viewport), use container queries:
```css
/* Define a container */
.md3-card-container {
container-type: inline-size;
container-name: card;
}
/* Respond to container width */
@container card (min-width: 400px) {
.md3-card {
flex-direction: row; /* Horizontal layout when container is wide */
}
}
@container card (max-width: 399px) {
.md3-card {
flex-direction: column; /* Vertical layout when narrow */
}
}
```
## Adaptive Component Behavior
Components transform across breakpoints:
| Component | Compact | Medium (incl. foldable unfolded) | Expanded+ / Large screen |
|-----------|---------|--------|-----------|
| Navigation | Bottom bar | Side rail | Side drawer |
| App bar | Small (64dp) | Small (64dp) | Small or Medium (112dp) |
| Dialog | Full-screen | Centered dialog | Centered dialog (max 560dp wide) |
| Bottom sheet | Full height | Partial height | Side sheet |
| Search | Full-screen search view | Persistent search bar | Persistent search bar |
| Cards | Full-width single column | Multi-column grid | Multi-column grid (max 4 cols) |
| Content panes | Single pane | Optional second pane | Two or three panes |
| Input method | Touch only | Touch + stylus | Touch + mouse/trackpad + keyboard |
## Complete App Layout Example
```html
<div class="md3-app-layout">
<!-- Navigation (responsive — see navigation-patterns.md) -->
<nav class="md3-nav" aria-label="Main navigation">
<!-- Nav content varies by breakpoint -->
</nav>
<!-- Main area -->
<div class="md3-main-area">
<!-- Top app bar -->
<header class="md3-top-app-bar">
<h1 class="md3-top-app-bar__title">Dashboard</h1>
</header>
<!-- Content area with canonical layout -->
<main class="md3-content-area">
<!-- Use feed, list-detail, or supporting pane here -->
</main>
</div>
</div>
```
```css
.md3-app-layout {
display: flex;
min-height: 100vh;
background: var(--md-sys-color-surface);
color: var(--md-sys-color-on-surface);
}
.md3-main-area {
flex: 1;
display: flex;
flex-direction: column;
min-width: 0; /* Prevent flex overflow */
}
.md3-content-area {
flex: 1;
overflow-y: auto;
}
/* Compact: stack vertically */
@media (max-width: 599px) {
.md3-app-layout { flex-direction: column; }
.md3-content-area { padding: 16px; }
}
/* Medium */
@media (min-width: 600px) and (max-width: 839px) {
.md3-content-area { padding: 24px; }
}
/* Expanded+ */
@media (min-width: 840px) {
.md3-content-area { padding: 24px; }
}
/* Large+: constrain max content width */
@media (min-width: 1200px) {
.md3-content-area {
max-width: 1040px;
margin: 0 auto;
padding: 24px;
}
}
```
## Foldables and Large Screens
MD3 provides specific guidance for foldable devices, tablets, and large-screen form factors. These are first-class targets in Material Design 3 — not afterthoughts.
### Foldable Postures
Foldable devices introduce postures that don't exist on traditional phones:
| Posture | Description | Layout behavior |
|---------|-------------|----------------|
| **Flat (unfolded)** | Device fully open, single large screen | Treat as Medium or Expanded window class based on width |
| **Half-opened (tabletop)** | Folded ~90° horizontally, bottom half on table | Split content at the hinge — video/image on top half, controls/info on bottom half |
| **Half-opened (book)** | Folded ~90° vertically, held like a book | Split content at the hinge — list on one side, detail on the other |
| **Folded** | Device closed, outer/cover screen | Treat as Compact — show essential content only |
### Hinge-Aware Layouts
The fold/hinge is a physical divider. Never place interactive content or critical information across the hinge area.
**Web — CSS Viewport Segments API:**
```css
/* Detect a dual-screen / foldable device with two horizontal segments */
@media (horizontal-viewport-segments: 2) {
.md3-list-detail {
flex-direction: row;
}
.md3-list-detail__list {
/* Span the left segment */
width: env(viewport-segment-width 0 0);
margin-right: env(viewport-segment-left 1 0, 0px) - env(viewport-segment-right 0 0, 0px);
}
.md3-list-detail__detail {
flex: 1;
}
}
/* Detect tabletop posture (two vertical segments) */
@media (vertical-viewport-segments: 2) {
.md3-media-player {
display: flex;
flex-direction: column;
}
.md3-media-player__video {
height: env(viewport-segment-height 0 0);
}
.md3-media-player__controls {
flex: 1;
}
}
```
**Flutter — `MediaQuery` and display features:**
```dart
Widget build(BuildContext context) {
final displayFeatures = MediaQuery.of(context).displayFeatures;
final hinge = displayFeatures.whereType<DisplayFeature>().where(
(f) => f.type == DisplayFeatureType.hinge || f.type == DisplayFeatureType.fold,
).firstOrNull;
if (hinge != null) {
// Foldable device — split at the hinge
return TwoPane(
startPane: ListPane(),
endPane: DetailPane(),
paneProportion: 0.5,
panePriority: isPortrait ? TwoPanePriority.start : TwoPanePriority.both,
);
}
// Single screen — use window size class
final width = MediaQuery.sizeOf(context).width;
if (width < 600) return CompactLayout();
if (width < 840) return MediumLayout();
return ExpandedLayout();
}
```
**Jetpack Compose — `WindowInfoTracker` and `FoldingFeature`:**
```kotlin
@Composable
fun AdaptiveLayout() {
val windowInfo = WindowInfoTracker.getOrCreate(LocalContext.current)
.windowLayoutInfo(LocalContext.current as Activity)
.collectAsState(initial = WindowLayoutInfo(emptyList()))
val foldingFeature = windowInfo.value.displayFeatures
.filterIsInstance<FoldingFeature>()
.firstOrNull()
when {
foldingFeature != null && foldingFeature.state == FoldingFeature.State.HALF_OPENED -> {
// Tabletop or book posture
if (foldingFeature.orientation == FoldingFeature.Orientation.HORIZONTAL) {
TabletopLayout(foldingFeature) // top: content, bottom: controls
} else {
BookLayout(foldingFeature) // left: list, right: detail
}
}
else -> {
// Standard adaptive layout based on window size class
val windowSizeClass = calculateWindowSizeClass(LocalContext.current as Activity)
StandardAdaptiveLayout(windowSizeClass)
}
}
}
```
### Tabletop Posture Pattern
When the device is in tabletop posture (horizontal fold, bottom half resting on a surface), the content naturally divides into two halves:
```
┌─────────────────────┐
│ │ ← Top half: visual content
│ Video / Image / │ (camera viewfinder, video player,
│ Primary content │ image gallery, map)
│ │
├─ ─ ─ hinge ─ ─ ─ ─ ┤
│ │ ← Bottom half: controls & info
│ Controls / Text / │ (playback controls, chat input,
│ Supporting info │ product details, toolbar)
│ │
└─────────────────────┘
```
### Book Posture Pattern
When the device is in book posture (vertical fold, held like a book), it naturally maps to list-detail:
```
┌──────────┬──────────┐
│ │ │
│ List / │ Detail │
│ Nav / │ Content │
│ Browse │ / Edit │
│ │ │
└──────────┴──────────┘
hinge
```
### Large Screen Layout Guidance
For tablets, Chromebooks, desktop, and large foldables (Expanded, Large, Extra-large):
**Content width constraints:**
- Don't stretch content to fill ultra-wide screens — reading lines longer than ~80 characters become hard to scan
- Constrain body content to a max width (typically 840–1040dp) and center it
- Use the extra space for multi-pane layouts, not wider single columns
```css
/* Constrain content on large screens */
@media (min-width: 1200px) {
.md3-content-area {
max-width: 1040px;
margin-inline: auto;
}
}
```
**Multi-pane strategies by window class:**
| Window class | Columns | Recommended layout |
|-------------|---------|-------------------|
| Compact (<600dp) | 4 | Single pane. Full-screen navigation between views. |
| Medium (600–839dp) | 8 | Optional second pane. List-detail with narrow list. Rail navigation. |
| Expanded (840–1199dp) | 12 | Two panes standard. List-detail or supporting pane. Drawer navigation. |
| Large (1200–1599dp) | 12 | Two or three panes. Feed with side panel. Persistent supporting pane. |
| Extra-large (1600dp+) | 12 | Three panes or constrained two-pane with generous margins. |
**Input and interaction differences:**
- Large screens often have mouse/trackpad input — hover states and right-click menus matter
- Touch targets remain 48dp minimum but can be supplemented with hover tooltips
- Keyboard shortcuts become expected on desktop-class devices
- Drag-and-drop is more natural on large screens
```css
/* Add hover states for pointer devices */
@media (hover: hover) {
.md3-card:hover {
background: color-mix(
in srgb,
var(--md-sys-color-on-surface) 8%,
var(--md-sys-color-surface)
);
}
.md3-list-item:hover {
background: color-mix(
in srgb,
var(--md-sys-color-on-surface) 8%,
transparent
);
}
}
/* Ensure pointer-specific affordances */
@media (pointer: fine) {
/* Scrollbars, resize handles, tighter spacing are acceptable */
.md3-drag-handle { cursor: col-resize; }
}
```
**Flutter — adaptive input:**
```dart
Widget build(BuildContext context) {
final width = MediaQuery.sizeOf(context).width;
final isLargeScreen = width >= 840;
return Scaffold(
body: Row(
children: [
// Navigation adapts
if (isLargeScreen)
NavigationRail(
destinations: destinations,
selectedIndex: selectedIndex,
onDestinationSelected: onSelected,
labelType: NavigationRailLabelType.all,
leading: FloatingActionButton(
onPressed: onCompose,
child: const Icon(Icons.edit),
),
),
// Content fills remaining space
Expanded(
child: isLargeScreen
? Row(
children: [
SizedBox(width: 360, child: ListPane()),
const VerticalDivider(width: 1),
Expanded(child: DetailPane()),
],
)
: selectedItem == null
? ListPane()
: DetailPane(),
),
],
),
bottomNavigationBar: isLargeScreen
? null
: NavigationBar(
destinations: destinations.map((d) =>
NavigationDestination(icon: d.icon, label: d.label)).toList(),
selectedIndex: selectedIndex,
onDestinationSelected: onSelected,
),
);
}
```
### Foldable-Aware Canonical Layouts
The three canonical layouts adapt naturally to foldables:
| Layout | Foldable behavior |
|--------|------------------|
| **Feed** | Unfolded: multi-column grid fills both halves. Tabletop: grid on top, selected item preview on bottom. |
| **List-detail** | Book posture: list on left half, detail on right half — a perfect natural fit. Tabletop: list on top, detail on bottom. |
| **Supporting pane** | Book posture: primary on left, supporting on right. Tabletop: primary on top, supporting controls on bottom. |
### Testing Large Screens and Foldables
**Web:**
- Use Chrome DevTools responsive mode to test at 600, 840, 1200, and 1600px breakpoints
- Test with pointer: coarse (touch) and pointer: fine (mouse) media queries
- Verify content doesn't stretch beyond readable line lengths at 1600px+
**Flutter:**
- Use `DevicePreview` package to simulate foldables and tablets
- Test with `MediaQuery` overrides for `displayFeatures`
- Run on Android emulators: Pixel Fold, 7.6" foldable, 10" tablet, Chromebook
**Compose:**
- Use Android Studio foldable emulators (Pixel Fold, 7.6" Foldable)
- Test posture changes: flat → half-opened → folded
- Use `WindowInfoTracker` to verify fold-aware layout switching
### Audit Checklist for Foldable/Large Screen Support
When auditing, check these specific items:
- [ ] App uses `MediaQuery.sizeOf(context).width` or equivalent to determine window size class
- [ ] Layout switches from single-pane to multi-pane at 600dp
- [ ] Navigation transforms: bottom bar → rail → drawer across breakpoints
- [ ] Content has max-width constraint on large screens (not stretching to fill)
- [ ] No critical content or interactive elements placed across a fold/hinge
- [ ] Foldable postures handled (if targeting foldable devices): tabletop and book modes
- [ ] Hover states exist for pointer devices (`@media (hover: hover)`)
- [ ] Touch targets remain 48dp minimum even on large screens
- [ ] Dialogs are centered (not full-screen) on medium+ screens
- [ ] Bottom sheets convert to side sheets on expanded+ screens
## Spacing System
MD3 uses a 4dp base grid for spacing:
| Use | Values |
|-----|--------|
| Component internal padding | 4, 8, 12, 16, 24dp |
| Between components | 8, 12, 16, 24dp |
| Section spacing | 24, 32, 48dp |
| Layout margins | 16dp (compact), 24dp (medium+) |
| Grid gutters | 8dp (compact), 16dp (medium), 24dp (large+) |
Always use multiples of 4dp for consistent spatial rhythm.

View File

@@ -0,0 +1,546 @@
# MD3 Navigation Patterns
Guide for choosing and implementing Material Design 3 navigation components.
## Jetpack Compose (primary)
Use **`androidx.compose.material3`**: `NavigationBar`, `NavigationRail`, `NavigationDrawerItem`, `ModalNavigationDrawer`, `DismissibleNavigationDrawer`, `PermanentNavigationDrawer`, `NavigationBarItem`, `NavigationRailItem`, top app bars (`TopAppBar`, `CenterAlignedTopAppBar`, `LargeTopAppBar`, expressive variants per BOM), and **`Scaffold`** (`bottomBar`, `floatingActionButton`, `snackbarHost`).
Wire destinations with **Navigation Compose** (`NavHost`, `composable`, `rememberNavController`). For **adaptive** UIs, use **`calculateWindowSizeClass`**, **`androidx.compose.material3.adaptive`**, or **`currentWindowAdaptiveInfo`** / **`NavigableListDetailPaneScaffold`** (names and packages depend on your BOM — check [Android Developers](https://developer.android.com/jetpack/androidx/releases/compose-material3)).
Material's [I/O 2026 update](https://m3.material.io/blog/whats-new-at-io26) adds expressive/adaptive emphasis:
- Prefer expressive/adaptive scaffolds for mobile, desktop, foldables, watches, and XR rather than scaling one phone navigation model upward.
- Expressive search and search app bars have refreshed visual style, motion, and more flexible trailing icon behavior. Use current Compose Material3 APIs where available; use web/CSS approximations only when targeting web.
- Keep navigation spacing on the 8dp spacing system so rail/drawer/app-bar gaps can adapt by device class and density.
```kotlin
// Conceptual — adapt routes and selection to your app
Scaffold(
bottomBar = {
NavigationBar {
destinations.forEach { dest ->
NavigationBarItem(
selected = currentRoute == dest.route,
onClick = { navController.navigate(dest.route) },
icon = { Icon(dest.icon, contentDescription = dest.label) },
label = { Text(dest.label) }
)
}
}
}
) { innerPadding ->
NavHost(
navController = navController,
startDestination = "home",
modifier = Modifier.padding(innerPadding)
) { /* composable routes */ }
}
```
**Web (limited):** The HTML/`@material/web` sections below remain useful for token-backed sites; [Material Web is maintenance-only](https://m3.material.io/develop/web).
---
## Navigation Component Selection
### Decision Tree
```
How many primary destinations?
├── 2 destinations → Tabs (primary)
├── 3–5 destinations
│ ├── Compact screen (<600dp) → Navigation Bar (bottom)
│ ├── Medium screen (600–839dp) → Navigation Rail (side)
│ └── Expanded+ screen (840dp+) → Navigation Drawer (side) or Rail
├── 6+ destinations
│ ├── Compact → Navigation Drawer (modal)
│ ├── Medium → Navigation Drawer (standard) or Rail + overflow menu
│ └── Expanded+ → Navigation Drawer (standard)
└── Hierarchical (nested sections)
└── Navigation Drawer with sections
```
### Quick Reference
| Component | Destinations | Screen Size | Persistence | Position |
|-----------|-------------|-------------|-------------|----------|
| Navigation Bar | 3–5 | Compact | Persistent | Bottom |
| Navigation Rail | 3–7 | Medium | Persistent | Side (start) |
| Navigation Drawer | Unlimited | Expanded+ | Standard or Modal | Side (start) |
| Tabs | 2+ related views | Any | Persistent | Top (below app bar) |
| Bottom App Bar | — (contextual actions) | Compact | Persistent | Bottom |
## Navigation Bar
**Use when**: 3–5 primary destinations on compact (mobile) screens.
**Position**: Bottom of screen, always visible.
### Anatomy
- Fixed at bottom, full width
- 3–5 navigation items with icon + label
- Active item shows filled icon + indicator pill
- Height: 80dp
### Implementation
```html
<md-navigation-bar active-index="0">
<md-navigation-tab label="Home" active-icon="home" inactive-icon="home">
<md-icon slot="active-icon">home</md-icon>
<md-icon slot="inactive-icon">home</md-icon>
</md-navigation-tab>
<md-navigation-tab label="Search">
<md-icon slot="active-icon">search</md-icon>
<md-icon slot="inactive-icon">search</md-icon>
</md-navigation-tab>
<md-navigation-tab label="Notifications">
<md-icon slot="active-icon">notifications</md-icon>
<md-icon slot="inactive-icon">notifications</md-icon>
</md-navigation-tab>
<md-navigation-tab label="Profile">
<md-icon slot="active-icon">person</md-icon>
<md-icon slot="inactive-icon">person</md-icon>
</md-navigation-tab>
</md-navigation-bar>
```
### Styling
```css
md-navigation-bar {
--md-navigation-bar-container-color: var(--md-sys-color-surface-container);
}
```
### Guidelines
- Always show labels (don't use icon-only)
- Use filled icons for active state, outlined for inactive
- Don't use for fewer than 3 or more than 5 destinations
- Hide on scroll down in content-heavy screens (optional)
- Elevation level 2 (3dp)
## Navigation Rail
**Use when**: 3–7 primary destinations on medium screens (tablets).
**Position**: Start edge (left in LTR), always visible.
### Anatomy
- Width: 80dp
- Optional FAB at top
- Navigation items vertically stacked
- Active item shows indicator pill
### Implementation
```html
<nav class="md3-nav-rail" aria-label="Main navigation">
<!-- Optional FAB -->
<md-fab size="small" variant="tertiary" aria-label="Compose">
<md-icon slot="icon">edit</md-icon>
</md-fab>
<div class="md3-nav-rail__items" role="tablist">
<a href="/" class="md3-nav-rail__item" role="tab" aria-selected="true" aria-current="page">
<div class="md3-nav-rail__indicator">
<md-icon>home</md-icon>
</div>
<span class="md3-nav-rail__label">Home</span>
</a>
<a href="/search" class="md3-nav-rail__item" role="tab" aria-selected="false">
<div class="md3-nav-rail__indicator">
<md-icon>search</md-icon>
</div>
<span class="md3-nav-rail__label">Search</span>
</a>
<a href="/settings" class="md3-nav-rail__item" role="tab" aria-selected="false">
<div class="md3-nav-rail__indicator">
<md-icon>settings</md-icon>
</div>
<span class="md3-nav-rail__label">Settings</span>
</a>
</div>
</nav>
```
```css
.md3-nav-rail {
width: 80px;
display: flex;
flex-direction: column;
align-items: center;
padding: 12px 0;
gap: 12px;
background: var(--md-sys-color-surface);
border-right: 1px solid var(--md-sys-color-outline-variant);
}
.md3-nav-rail__items {
display: flex;
flex-direction: column;
gap: 12px;
align-items: center;
}
.md3-nav-rail__item {
display: flex;
flex-direction: column;
align-items: center;
gap: 4px;
text-decoration: none;
color: var(--md-sys-color-on-surface-variant);
font: var(--md-sys-typescale-label-medium);
cursor: pointer;
width: 56px;
}
.md3-nav-rail__indicator {
width: 56px;
height: 32px;
display: flex;
align-items: center;
justify-content: center;
border-radius: var(--md-sys-shape-corner-full);
}
.md3-nav-rail__item[aria-selected="true"] .md3-nav-rail__indicator {
background: var(--md-sys-color-secondary-container);
color: var(--md-sys-color-on-secondary-container);
}
.md3-nav-rail__item[aria-selected="true"] {
color: var(--md-sys-color-on-surface);
}
```
### Guidelines
- Align items to top (below optional FAB)
- Show labels always (optional to hide, but recommended to show)
- FAB at top is optional but common
- Elevation level 0
## Navigation Drawer
**Use when**: Many destinations, expanded screens, or deep hierarchies.
**Position**: Start edge, standard (persistent) or modal (overlay).
### Standard Drawer (Persistent)
Always visible alongside content. Width: 360dp.
```html
<div class="md3-layout">
<md-navigation-drawer opened>
<div slot="headline">App Name</div>
<md-list>
<md-list-item type="button" active>
<md-icon slot="start">inbox</md-icon>
<div slot="headline">Inbox</div>
<div slot="trailing-supporting-text">24</div>
</md-list-item>
<md-list-item type="button">
<md-icon slot="start">send</md-icon>
<div slot="headline">Sent</div>
</md-list-item>
<md-divider></md-divider>
<md-list-item type="button">
<md-icon slot="start">drafts</md-icon>
<div slot="headline">Drafts</div>
</md-list-item>
</md-list>
</md-navigation-drawer>
<main class="md3-content">
<!-- Page content -->
</main>
</div>
```
### Modal Drawer (Overlay)
Overlays content with a scrim. Used on smaller screens or when content space is limited.
```html
<md-navigation-drawer type="modal" id="nav-drawer">
<!-- Same content as standard -->
</md-navigation-drawer>
<script>
// Toggle drawer
document.getElementById('menu-btn').addEventListener('click', () => {
const drawer = document.getElementById('nav-drawer');
drawer.opened = !drawer.opened;
});
</script>
```
### Guidelines
- Standard drawer uses `surface-container` background
- Modal drawer has elevation level 1 and scrim overlay
- Group destinations with dividers and section headers
- Active item uses `secondary-container` background
- Shape: `large` on end corners (right edge in LTR)
## Top App Bar
**Use when**: Every screen needs a title and optional actions.
**I/O 2026 note:** Search app bars are part of the current expressive search guidance. In Compose, check your Material3 BOM for expressive app bar and search APIs before hand-rolling. For web, combine a token-backed top app bar with a custom search field/view because Material Web does not expose full expressive search parity.
### Variants
| Variant | Title | Height | Scroll Behavior |
|---------|-------|--------|----------------|
| Center-aligned | Center | 64dp | Elevates to level 2 on scroll |
| Small | Start-aligned | 64dp | Elevates to level 2 on scroll |
| Medium | Bottom, start-aligned | 112dp | Collapses to 64dp on scroll |
| Large | Bottom, start-aligned | 152dp | Collapses to 64dp on scroll |
### Implementation
```html
<!-- Small app bar -->
<header class="md3-top-app-bar">
<md-icon-button aria-label="Open menu">
<md-icon>menu</md-icon>
</md-icon-button>
<h1 class="md3-top-app-bar__title">Page Title</h1>
<md-icon-button aria-label="Search">
<md-icon>search</md-icon>
</md-icon-button>
<md-icon-button aria-label="More options">
<md-icon>more_vert</md-icon>
</md-icon-button>
</header>
<!-- Medium app bar (collapsed state shown; expand on scroll-to-top) -->
<header class="md3-top-app-bar md3-top-app-bar--medium">
<div class="md3-top-app-bar__row">
<md-icon-button aria-label="Back"><md-icon>arrow_back</md-icon></md-icon-button>
<span class="md3-top-app-bar__title-collapsed"></span>
<md-icon-button aria-label="More"><md-icon>more_vert</md-icon></md-icon-button>
</div>
<div class="md3-top-app-bar__expanded-title">
<h1>Page Title</h1>
</div>
</header>
```
```css
.md3-top-app-bar {
display: flex;
align-items: center;
height: 64px;
padding: 0 4px;
background: var(--md-sys-color-surface);
color: var(--md-sys-color-on-surface);
}
.md3-top-app-bar__title {
flex: 1;
padding: 0 12px;
font: var(--md-sys-typescale-title-large);
margin: 0;
}
/* Scrolled state: elevate */
.md3-top-app-bar--scrolled {
background: var(--md-sys-color-surface-container);
}
```
### Scroll Behavior
```javascript
// Elevate app bar on scroll
const appBar = document.querySelector('.md3-top-app-bar');
window.addEventListener('scroll', () => {
appBar.classList.toggle('md3-top-app-bar--scrolled', window.scrollY > 0);
});
```
## Tabs
**Use when**: Switching between related content at the same hierarchy level.
### Primary vs Secondary
- **Primary tabs**: Top-level content switching (Flights / Hotels / Explore)
- **Secondary tabs**: Sub-sections within primary content
```html
<!-- Primary tabs -->
<md-tabs>
<md-primary-tab active>
<md-icon slot="icon">flight</md-icon>
Flights
</md-primary-tab>
<md-primary-tab>Hotels</md-primary-tab>
<md-primary-tab>Car Rental</md-primary-tab>
</md-tabs>
<!-- Secondary tabs (nested under primary) -->
<md-tabs>
<md-secondary-tab active>Overview</md-secondary-tab>
<md-secondary-tab>Reviews</md-secondary-tab>
<md-secondary-tab>Photos</md-secondary-tab>
</md-tabs>
```
### Tab + Panel Connection
```html
<md-tabs id="my-tabs">
<md-primary-tab id="tab-1" aria-controls="panel-1" active>Tab 1</md-primary-tab>
<md-primary-tab id="tab-2" aria-controls="panel-2">Tab 2</md-primary-tab>
</md-tabs>
<div id="panel-1" role="tabpanel" aria-labelledby="tab-1">
Panel 1 content
</div>
<div id="panel-2" role="tabpanel" aria-labelledby="tab-2" hidden>
Panel 2 content
</div>
<script>
document.getElementById('my-tabs').addEventListener('change', (e) => {
// Hide all panels
document.querySelectorAll('[role="tabpanel"]').forEach(p => p.hidden = true);
// Show selected panel
const activeTab = e.target.querySelector('[active]');
const panelId = activeTab.getAttribute('aria-controls');
document.getElementById(panelId).hidden = false;
});
</script>
```
## Responsive Navigation Pattern
The key MD3 pattern: navigation component transforms across breakpoints.
### Mobile → Tablet → Desktop
```
Compact (<600dp): Navigation Bar (bottom)
Medium (600–839dp): Navigation Rail (side)
Expanded (840dp+): Navigation Drawer (side, standard)
```
### CSS Implementation
```css
/* Hide all nav variants by default */
.md3-nav-bar,
.md3-nav-rail,
.md3-nav-drawer { display: none; }
/* Compact: show bottom navigation bar */
@media (max-width: 599px) {
.md3-nav-bar { display: flex; }
.md3-app { flex-direction: column; }
}
/* Medium: show navigation rail */
@media (min-width: 600px) and (max-width: 839px) {
.md3-nav-rail { display: flex; }
.md3-app { flex-direction: row; }
}
/* Expanded+: show navigation drawer */
@media (min-width: 840px) {
.md3-nav-drawer { display: flex; }
.md3-app { flex-direction: row; }
}
```
### Complete Responsive Shell
```html
<div class="md3-app">
<!-- Navigation drawer (expanded+) -->
<aside class="md3-nav-drawer">
<md-navigation-drawer opened>
<div slot="headline">My App</div>
<md-list>
<md-list-item type="button" active>
<md-icon slot="start">home</md-icon>Home
</md-list-item>
<md-list-item type="button">
<md-icon slot="start">search</md-icon>Search
</md-list-item>
<md-list-item type="button">
<md-icon slot="start">settings</md-icon>Settings
</md-list-item>
</md-list>
</md-navigation-drawer>
</aside>
<!-- Navigation rail (medium) -->
<nav class="md3-nav-rail" aria-label="Main">
<md-fab size="small" aria-label="New"><md-icon slot="icon">add</md-icon></md-fab>
<a class="md3-nav-rail__item active"><md-icon>home</md-icon><span>Home</span></a>
<a class="md3-nav-rail__item"><md-icon>search</md-icon><span>Search</span></a>
<a class="md3-nav-rail__item"><md-icon>settings</md-icon><span>Settings</span></a>
</nav>
<!-- Main content -->
<main class="md3-main">
<header class="md3-top-app-bar">
<md-icon-button class="md3-menu-btn" aria-label="Menu"><md-icon>menu</md-icon></md-icon-button>
<h1 class="md3-top-app-bar__title">Home</h1>
</header>
<div class="md3-body">
<!-- Page content -->
</div>
</main>
<!-- Navigation bar (compact) -->
<md-navigation-bar class="md3-nav-bar">
<md-navigation-tab label="Home" active>
<md-icon slot="active-icon">home</md-icon>
<md-icon slot="inactive-icon">home</md-icon>
</md-navigation-tab>
<md-navigation-tab label="Search">
<md-icon slot="active-icon">search</md-icon>
<md-icon slot="inactive-icon">search</md-icon>
</md-navigation-tab>
<md-navigation-tab label="Settings">
<md-icon slot="active-icon">settings</md-icon>
<md-icon slot="inactive-icon">settings</md-icon>
</md-navigation-tab>
</md-navigation-bar>
</div>
```
```css
.md3-app {
display: flex;
min-height: 100vh;
background: var(--md-sys-color-surface);
color: var(--md-sys-color-on-surface);
}
.md3-main { flex: 1; display: flex; flex-direction: column; }
.md3-body { flex: 1; padding: 16px; }
/* Compact */
@media (max-width: 599px) {
.md3-app { flex-direction: column; }
.md3-nav-rail, .md3-nav-drawer { display: none; }
.md3-nav-bar { display: flex; order: 1; }
.md3-menu-btn { display: none; }
}
/* Medium */
@media (min-width: 600px) and (max-width: 839px) {
.md3-nav-bar, .md3-nav-drawer { display: none; }
.md3-nav-rail { display: flex; }
.md3-menu-btn { display: none; }
}
/* Expanded+ */
@media (min-width: 840px) {
.md3-nav-bar, .md3-nav-rail { display: none; }
.md3-nav-drawer { display: flex; }
.md3-menu-btn { display: none; }
}
```

View File

@@ -0,0 +1,484 @@
# MD3 Theming and Dynamic Color
Complete guide to creating, applying, and managing Material Design 3 themes.
## Theme Architecture
The same **semantic roles** (primary, onSurface, surface containers, etc.) appear on every platform:
| Platform | Theme surface |
|----------|----------------|
| **Jetpack Compose** | `MaterialTheme(colorScheme, typography, shapes, …)` |
| **Flutter** | `ThemeData` + `ColorScheme`, `useMaterial3: true` |
| **Web** | CSS custom properties `--md-sys-*` on `:root` or a subtree |
**Web:** [Material Web is maintenance-only; M3 Expressive is not implemented on Web](https://m3.material.io/develop/web). Use `@material/web` + CSS knowing the stack is limited.
---
## Jetpack Compose Theming
Use `androidx.compose.material3.MaterialTheme`. Prefer **dynamic color** on **Android 12+ (API 31+)** when enabled; otherwise use `lightColorScheme` / `darkColorScheme` or Kotlin generated by [Material Theme Builder](https://material-foundation.github.io/material-theme-builder/).
```kotlin
import androidx.compose.material3.*
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.ui.platform.LocalContext
@Composable
fun MyAppTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
dynamicColor: Boolean = true,
content: @Composable () -> Unit
) {
val colorScheme = when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}
darkTheme -> darkColorScheme(
primary = Color(0xFFD0BCFF),
onPrimary = Color(0xFF381E72),
// … add remaining roles or use generated Theme.kt
)
else -> lightColorScheme(
primary = Color(0xFF6750A4),
onPrimary = Color(0xFFFFFFFF),
// … add remaining roles or use generated Theme.kt
)
}
MaterialTheme(
colorScheme = colorScheme,
typography = Typography(),
shapes = Shapes(),
content = content
)
}
```
---
## Flutter Theming
```dart
import 'package:flutter/material.dart';
// Basic MD3 theme from seed
MaterialApp(
theme: ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.deepPurple,
brightness: Brightness.light,
),
),
darkTheme: ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.deepPurple,
brightness: Brightness.dark,
),
),
);
// Dynamic color (Android 12+)
// Requires package:dynamic_color
DynamicColorBuilder(
builder: (lightDynamic, darkDynamic) {
return MaterialApp(
theme: ThemeData(
useMaterial3: true,
colorScheme: lightDynamic ?? ColorScheme.fromSeed(seedColor: Colors.deepPurple),
),
darkTheme: ThemeData(
useMaterial3: true,
colorScheme: darkDynamic ?? ColorScheme.fromSeed(
seedColor: Colors.deepPurple,
brightness: Brightness.dark,
),
),
);
},
);
```
---
## Web: Theme Builder and CSS
### 1. Choose a Seed Color
Start with a single hex color that represents your brand. The entire scheme generates from this seed.
### 2. Generate the Scheme
Use `@material/material-color-utilities` to generate light and dark schemes:
```bash
npm install @material/material-color-utilities
```
```javascript
import {
argbFromHex,
hexFromArgb,
SchemeContent,
Hct,
} from '@material/material-color-utilities';
function generateTheme(seedHex, isDark = false, contrast = 0.0) {
const hct = Hct.fromInt(argbFromHex(seedHex));
const scheme = new SchemeContent(hct, isDark, contrast);
return {
// Primary
'--md-sys-color-primary': hexFromArgb(scheme.primary),
'--md-sys-color-on-primary': hexFromArgb(scheme.onPrimary),
'--md-sys-color-primary-container': hexFromArgb(scheme.primaryContainer),
'--md-sys-color-on-primary-container': hexFromArgb(scheme.onPrimaryContainer),
// Secondary
'--md-sys-color-secondary': hexFromArgb(scheme.secondary),
'--md-sys-color-on-secondary': hexFromArgb(scheme.onSecondary),
'--md-sys-color-secondary-container': hexFromArgb(scheme.secondaryContainer),
'--md-sys-color-on-secondary-container': hexFromArgb(scheme.onSecondaryContainer),
// Tertiary
'--md-sys-color-tertiary': hexFromArgb(scheme.tertiary),
'--md-sys-color-on-tertiary': hexFromArgb(scheme.onTertiary),
'--md-sys-color-tertiary-container': hexFromArgb(scheme.tertiaryContainer),
'--md-sys-color-on-tertiary-container': hexFromArgb(scheme.onTertiaryContainer),
// Error
'--md-sys-color-error': hexFromArgb(scheme.error),
'--md-sys-color-on-error': hexFromArgb(scheme.onError),
'--md-sys-color-error-container': hexFromArgb(scheme.errorContainer),
'--md-sys-color-on-error-container': hexFromArgb(scheme.onErrorContainer),
// Surface
'--md-sys-color-surface': hexFromArgb(scheme.surface),
'--md-sys-color-on-surface': hexFromArgb(scheme.onSurface),
'--md-sys-color-on-surface-variant': hexFromArgb(scheme.onSurfaceVariant),
'--md-sys-color-surface-container-lowest': hexFromArgb(scheme.surfaceContainerLowest),
'--md-sys-color-surface-container-low': hexFromArgb(scheme.surfaceContainerLow),
'--md-sys-color-surface-container': hexFromArgb(scheme.surfaceContainer),
'--md-sys-color-surface-container-high': hexFromArgb(scheme.surfaceContainerHigh),
'--md-sys-color-surface-container-highest': hexFromArgb(scheme.surfaceContainerHighest),
'--md-sys-color-surface-dim': hexFromArgb(scheme.surfaceDim),
'--md-sys-color-surface-bright': hexFromArgb(scheme.surfaceBright),
// Outline
'--md-sys-color-outline': hexFromArgb(scheme.outline),
'--md-sys-color-outline-variant': hexFromArgb(scheme.outlineVariant),
// Inverse
'--md-sys-color-inverse-surface': hexFromArgb(scheme.inverseSurface),
'--md-sys-color-inverse-on-surface': hexFromArgb(scheme.inverseOnSurface),
'--md-sys-color-inverse-primary': hexFromArgb(scheme.inversePrimary),
};
}
```
### 3. Apply the Theme
```javascript
function applyTheme(seedHex, isDark = false, contrast = 0.0) {
const tokens = generateTheme(seedHex, isDark, contrast);
const root = document.documentElement;
for (const [prop, value] of Object.entries(tokens)) {
root.style.setProperty(prop, value);
}
}
// Apply light theme
applyTheme('#1A73E8');
// Apply dark theme
applyTheme('#1A73E8', true);
// Apply high contrast
applyTheme('#1A73E8', false, 1.0);
```
### 4. Export as CSS
```javascript
function exportAsCSS(seedHex) {
const light = generateTheme(seedHex, false);
const dark = generateTheme(seedHex, true);
let css = ':root {\n';
for (const [prop, value] of Object.entries(light)) {
css += ` ${prop}: ${value};\n`;
}
css += '}\n\n';
css += '@media (prefers-color-scheme: dark) {\n :root {\n';
for (const [prop, value] of Object.entries(dark)) {
css += ` ${prop}: ${value};\n`;
}
css += ' }\n}\n';
return css;
}
```
## Brand Color Integration
### Mapping Existing Brand Colors
If you have existing brand colors, map them to MD3 roles:
| Brand concept | MD3 role |
|--------------|----------|
| Primary brand color | Use as seed for `primary` palette |
| Secondary brand color | Override `secondary` or use as custom color |
| Accent color | Map to `tertiary` |
| Alert/danger color | Override `error` (or keep MD3 default) |
| Background | Generated from seed (don't hardcode) |
### Using a Brand Color as Seed
The simplest approach: use your primary brand color as the seed. The algorithm will generate harmonious secondary and tertiary colors automatically.
```javascript
// Your brand's primary blue
applyTheme('#1A73E8');
```
### Color Harmonization for Additional Brand Colors
If you need to integrate a specific brand color that wasn't generated from the seed:
```javascript
import { Blend, argbFromHex, hexFromArgb } from '@material/material-color-utilities';
// Your brand's orange accent color
const brandOrange = argbFromHex('#FF6D00');
// The generated primary color
const schemePrimary = argbFromHex('#1A73E8');
// Harmonize: shifts the hue slightly toward primary
const harmonizedOrange = hexFromArgb(Blend.harmonize(brandOrange, schemePrimary));
// Use harmonizedOrange as a custom color in your theme
```
## Dark Theme
### Automatic Generation
Dark theme is automatically generated from the same seed color. The tonal mapping simply shifts:
- Light theme uses lighter tones (80-100) for surfaces, darker tones (10-40) for accents
- Dark theme inverts: darker tones (4-22) for surfaces, lighter tones (80-90) for accents
### CSS Implementation
```css
/* Light theme (default) */
:root {
--md-sys-color-primary: #6750A4;
--md-sys-color-surface: #FEF7FF;
/* ... all light tokens ... */
}
/* Dark theme via media query */
@media (prefers-color-scheme: dark) {
:root {
--md-sys-color-primary: #D0BCFF;
--md-sys-color-surface: #141218;
/* ... all dark tokens ... */
}
}
/* Dark theme via class (for manual toggle) */
.dark-theme {
--md-sys-color-primary: #D0BCFF;
--md-sys-color-surface: #141218;
/* ... all dark tokens ... */
}
```
### Runtime Theme Switching
```javascript
class ThemeManager {
constructor(seedHex) {
this.seedHex = seedHex;
this.isDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
this.contrast = 0.0; // standard
// Listen for system theme changes
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
this.isDark = e.matches;
this.apply();
});
}
apply() {
const tokens = generateTheme(this.seedHex, this.isDark, this.contrast);
const root = document.documentElement;
for (const [prop, value] of Object.entries(tokens)) {
root.style.setProperty(prop, value);
}
root.setAttribute('data-theme', this.isDark ? 'dark' : 'light');
}
toggleDark() {
this.isDark = !this.isDark;
this.apply();
}
setContrast(level) {
// 0.0 = standard, 0.5 = medium, 1.0 = high
this.contrast = level;
this.apply();
}
setSeed(hex) {
this.seedHex = hex;
this.apply();
}
}
// Usage
const theme = new ThemeManager('#6750A4');
theme.apply();
// Toggle dark mode
document.getElementById('theme-toggle').addEventListener('click', () => theme.toggleDark());
```
## High Contrast Themes
MD3 supports 3 contrast levels, adjustable via the `contrast` parameter:
| Level | Value | Effect |
|-------|-------|--------|
| Standard | 0.0 | Default tonal distance |
| Medium | 0.5 | Increased tonal distance, easier to read |
| High | 1.0 | Maximum tonal distance, highest legibility |
```javascript
// Standard contrast
const standard = new SchemeContent(hct, isDark, 0.0);
// Medium contrast
const medium = new SchemeContent(hct, isDark, 0.5);
// High contrast
const high = new SchemeContent(hct, isDark, 1.0);
```
Higher contrast increases the tonal distance between paired color roles (e.g., `primary` and `on-primary`), making text more legible without fundamentally changing the color feel.
## Component-Level Overrides (web)
Override individual **web** component appearance using component-specific CSS custom properties. **Compose** uses `TextFieldDefaults`, `ButtonDefaults`, `MaterialTheme`, etc.
```css
/* Override specific button colors */
md-filled-button {
--md-filled-button-container-color: var(--md-sys-color-tertiary);
--md-filled-button-label-text-color: var(--md-sys-color-on-tertiary);
}
/* Override text field shape */
md-outlined-text-field {
--md-outlined-text-field-container-shape: var(--md-sys-shape-corner-medium);
}
/* Override FAB */
md-fab {
--md-fab-container-color: var(--md-sys-color-tertiary-container);
--md-fab-icon-color: var(--md-sys-color-on-tertiary-container);
}
/* Override switch colors */
md-switch {
--md-switch-selected-track-color: var(--md-sys-color-primary);
--md-switch-selected-handle-color: var(--md-sys-color-on-primary);
}
```
### Component Token Naming Pattern
Component tokens follow: `--md-{component}-{element}-{property}`
Examples:
- `--md-filled-button-container-color`
- `--md-filled-button-container-shape`
- `--md-filled-button-label-text-color`
- `--md-outlined-text-field-outline-color`
- `--md-outlined-text-field-focus-outline-color`
- `--md-fab-container-color`
- `--md-fab-container-shape`
- `--md-switch-selected-track-color`
## Dynamic Color from Content
Extract a color from an image and apply it as the theme:
```javascript
import {
QuantizerCelebi,
Score,
argbFromRgb,
} from '@material/material-color-utilities';
async function themeFromImage(imageUrl) {
const img = new Image();
img.crossOrigin = 'anonymous';
img.src = imageUrl;
await img.decode();
const canvas = document.createElement('canvas');
canvas.width = img.width;
canvas.height = img.height;
const ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0);
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
const pixels = [];
for (let i = 0; i < imageData.data.length; i += 4) {
pixels.push(argbFromRgb(imageData.data[i], imageData.data[i+1], imageData.data[i+2]));
}
// Quantize and score to find best seed color
const quantized = QuantizerCelebi.quantize(pixels, 128);
const scored = Score.score(quantized);
const seedColor = scored[0]; // Best color
return hexFromArgb(seedColor);
}
// Usage
const seed = await themeFromImage('/album-cover.jpg');
applyTheme(seed);
```
## Scoped Themes
Apply different themes to different sections of the UI:
```css
/* Default theme */
:root {
--md-sys-color-primary: #6750A4;
/* ... */
}
/* Scoped theme for a section */
.premium-section {
--md-sys-color-primary: #B69DF8;
--md-sys-color-primary-container: #3F2D7A;
/* Only override what changes */
}
```
```html
<main>
<!-- Uses default theme -->
<section class="regular">
<md-filled-button>Standard</md-filled-button>
</section>
<!-- Uses premium theme -->
<section class="premium-section">
<md-filled-button>Premium</md-filled-button>
</section>
</main>
```
CSS custom properties cascade, so child elements automatically inherit the closest ancestor's tokens.

View File

@@ -0,0 +1,400 @@
# MD3 Typography, Shape, Elevation, and Motion
Reference for Material Design 3's visual token systems beyond color.
## Typography
### Type Scale
MD3 uses 15 baseline styles + 15 emphasized styles organized in 5 categories (Display, Headline, Title, Body, Label) with 3 sizes each (Large, Medium, Small).
#### Baseline Type Scale (Default Values)
| Style | Font | Weight | Size (sp) | Size (rem) | Line Height | Tracking |
|-------|------|--------|-----------|------------|-------------|----------|
| Display Large | Roboto | 400 | 57 | 3.5625 | 64sp / 4rem | -0.25px |
| Display Medium | Roboto | 400 | 45 | 2.8125 | 52sp / 3.25rem | 0 |
| Display Small | Roboto | 400 | 36 | 2.25 | 44sp / 2.75rem | 0 |
| Headline Large | Roboto | 400 | 32 | 2 | 40sp / 2.5rem | 0 |
| Headline Medium | Roboto | 400 | 28 | 1.75 | 36sp / 2.25rem | 0 |
| Headline Small | Roboto | 400 | 24 | 1.5 | 32sp / 2rem | 0 |
| Title Large | Roboto | 400 | 22 | 1.375 | 28sp / 1.75rem | 0 |
| Title Medium | Roboto | 500 | 16 | 1 | 24sp / 1.5rem | 0.15px |
| Title Small | Roboto | 500 | 14 | 0.875 | 20sp / 1.25rem | 0.1px |
| Body Large | Roboto | 400 | 16 | 1 | 24sp / 1.5rem | 0.5px |
| Body Medium | Roboto | 400 | 14 | 0.875 | 20sp / 1.25rem | 0.25px |
| Body Small | Roboto | 400 | 12 | 0.75 | 16sp / 1rem | 0.4px |
| Label Large | Roboto | 500 | 14 | 0.875 | 20sp / 1.25rem | 0.1px |
| Label Medium | Roboto | 500 | 12 | 0.75 | 16sp / 1rem | 0.5px |
| Label Small | Roboto | 500 | 11 | 0.6875 | 16sp / 1rem | 0.5px |
#### Emphasized Type Styles (Expressive Update)
The 15 emphasized styles mirror the baseline scale but with **higher weight** and minor adjustments. Use for:
- Selected/active states in components
- Primary action buttons
- Headlines needing emphasis
- Unread/important content
To use: swap the baseline token for the emphasized version:
- Baseline: `md.sys.typescale.display-large`
- Emphasized: `md.sys.typescale.emphasized.display-large`
### CSS Custom Properties
Each type style maps to individual axis tokens:
```css
/* Example: Body Large */
--md-sys-typescale-body-large-font: 'Roboto', sans-serif;
--md-sys-typescale-body-large-weight: 400;
--md-sys-typescale-body-large-size: 1rem; /* 16sp */
--md-sys-typescale-body-large-line-height: 1.5rem; /* 24sp */
--md-sys-typescale-body-large-tracking: 0.03125rem; /* 0.5px */
/* Example: Title Medium */
--md-sys-typescale-title-medium-font: 'Roboto', sans-serif;
--md-sys-typescale-title-medium-weight: 500;
--md-sys-typescale-title-medium-size: 1rem;
--md-sys-typescale-title-medium-line-height: 1.5rem;
--md-sys-typescale-title-medium-tracking: 0.009375rem;
/* Example: Label Large (used for buttons) */
--md-sys-typescale-label-large-font: 'Roboto', sans-serif;
--md-sys-typescale-label-large-weight: 500;
--md-sys-typescale-label-large-size: 0.875rem;
--md-sys-typescale-label-large-line-height: 1.25rem;
--md-sys-typescale-label-large-tracking: 0.00625rem;
```
### Using Type Styles in CSS
Apply using individual properties:
```css
.headline {
font-family: var(--md-sys-typescale-headline-large-font);
font-weight: var(--md-sys-typescale-headline-large-weight);
font-size: var(--md-sys-typescale-headline-large-size);
line-height: var(--md-sys-typescale-headline-large-line-height);
letter-spacing: var(--md-sys-typescale-headline-large-tracking);
}
```
Or use the shorthand font property for convenience (note: requires defining the shorthand token):
```css
.headline {
font: var(--md-sys-typescale-headline-large-weight)
var(--md-sys-typescale-headline-large-size) /
var(--md-sys-typescale-headline-large-line-height)
var(--md-sys-typescale-headline-large-font);
letter-spacing: var(--md-sys-typescale-headline-large-tracking);
}
```
### Typeface Customization
MD3 uses two typeface roles:
- **Brand**: Used for Display and Headline styles (expression-focused)
- **Plain**: Used for Title, Body, and Label styles (readability-focused)
Both default to Roboto. To customize:
```css
:root {
/* Brand typeface for display/headline */
--md-ref-typeface-brand: 'Your Display Font', sans-serif;
/* Plain typeface for body/label/title */
--md-ref-typeface-plain: 'Your Body Font', sans-serif;
}
```
### Roboto Flex
Roboto Flex is a variable font supporting multiple axes:
- **Weight** (wght): 100–1000
- **Width** (wdth): 25–151
- **Optical size** (opsz): 8–144
```css
@font-face {
font-family: 'Roboto Flex';
src: url('RobotoFlex-VariableFont.woff2') format('woff2');
font-weight: 100 1000;
font-stretch: 25% 151%;
}
```
### Font Size Units
| Platform | Unit | Conversion |
|----------|------|------------|
| Android | sp | 1:1 |
| Web | rem | sp / 16 = rem (assuming 16px root) |
Examples: 10sp = 0.625rem, 12sp = 0.75rem, 14sp = 0.875rem, 16sp = 1rem, 24sp = 1.5rem
### Component Type Usage
| Component | Type Style |
|-----------|-----------|
| Button label | Label Large |
| Card title | Title Medium |
| Card body | Body Medium |
| Top app bar title | Title Large |
| Navigation label | Label Medium |
| Dialog headline | Headline Small |
| Dialog body | Body Medium |
| Chip label | Label Large |
| Text field input | Body Large |
| Text field label | Body Small (floating) / Body Large (resting) |
| List headline | Body Large |
| List supporting text | Body Medium |
| Snackbar text | Body Medium |
| Tooltip text | Body Small |
| Tab label | Title Small |
| Badge count | Label Small |
## Shape
### Corner Radius Scale
| Token | Value (dp) | Value (px/CSS) | Default components |
|-------|-----------|----------------|-------------------|
| `none` | 0 | 0px | — |
| `extra-small` | 4 | 4px | Snackbar |
| `small` | 8 | 8px | Text fields, menus, chips |
| `medium` | 12 | 12px | Cards |
| `large` | 16 | 16px | FAB, extended FAB, nav drawer |
| `large-increased` | 20 | 20px | (Expressive update) |
| `extra-large` | 28 | 28px | Dialogs, bottom sheets, side sheets |
| `extra-large-increased` | 32 | 32px | (Expressive update) |
| `extra-extra-large` | 48 | 48px | (Expressive update) |
| `full` | — | 9999px | Buttons, badges, pills, sliders |
### CSS Custom Properties
```css
:root {
--md-sys-shape-corner-none: 0px;
--md-sys-shape-corner-extra-small: 4px;
--md-sys-shape-corner-small: 8px;
--md-sys-shape-corner-medium: 12px;
--md-sys-shape-corner-large: 16px;
--md-sys-shape-corner-large-increased: 20px;
--md-sys-shape-corner-extra-large: 28px;
--md-sys-shape-corner-extra-large-increased: 32px;
--md-sys-shape-corner-extra-extra-large: 48px;
--md-sys-shape-corner-full: 9999px;
}
```
### Component Shape Mapping
| Component | Default Shape Token |
|-----------|-------------------|
| Buttons (all types) | `full` |
| FAB | `large` |
| Extended FAB | `large` |
| Icon button | `full` |
| Chips | `small` |
| Cards | `medium` |
| Dialogs | `extra-large` |
| Text fields | `small` (top corners) |
| Menus | `small` |
| Navigation drawer | `large` (end corners) |
| Bottom sheets | `extra-large` (top corners) |
| Snackbar | `extra-small` |
| Badges | `full` |
| Sliders (handle) | `full` |
| Switch (track) | `full` |
| Tabs (indicator) | `full` (top corners) |
| Search bar | `full` |
### Shape Morphing (Expressive)
In the M3 Expressive update, components can morph between shapes on interaction:
- Button shapes morph when pressed
- Selected states can change shape
- Loading indicators use shape morphing to show progress
**Platform notes**: Shape morphing is **not** in `@material/web` ([Material Web is maintenance-only; Expressive not on Web](https://m3.material.io/develop/web)). **Jetpack Compose** is where Google documents expressive shape/motion behavior for Android. **Flutter:** check current Material 3 / expressive docs for your SDK. **Web:** approximate with CSS transitions on `border-radius`.
## Elevation
### Elevation Levels
| Level | DP Height | Use |
|-------|-----------|-----|
| 0 | 0dp | Most resting components |
| 1 | 1dp | Elevated variants (cards, sheets) |
| 2 | 3dp | Menus, nav bar, scrolled app bar |
| 3 | 6dp | FAB, dialogs, search, date/time pickers |
| 4 | 8dp | Hover/focus increase only |
| 5 | 12dp | Hover/focus increase only |
### Tonal Elevation (Not Shadows)
MD3 uses **tonal surface color** to communicate elevation, not shadows. Higher elevation = lighter surface tone (in light theme) or lighter surface tone (in dark theme).
The surface container roles map to this concept:
- Level 0: `surface` (flattest)
- Level 1: `surface-container-low`
- Level 2: `surface-container`
- Level 3: `surface-container-high`
- Level 4-5: `surface-container-highest`
### When to Use Shadows
Shadows are only appropriate when:
- A component floats over content that may be visually busy (e.g., FAB over images)
- Additional depth cue is needed beyond color (e.g., overlapping elements)
- The platform convention expects shadows (some Android components)
### CSS Shadow Values
When shadows are needed:
```css
/* Level 1 */
box-shadow: 0 1px 2px rgba(0,0,0,0.3), 0 1px 3px 1px rgba(0,0,0,0.15);
/* Level 2 */
box-shadow: 0 1px 2px rgba(0,0,0,0.3), 0 2px 6px 2px rgba(0,0,0,0.15);
/* Level 3 */
box-shadow: 0 4px 8px 3px rgba(0,0,0,0.15), 0 1px 3px rgba(0,0,0,0.3);
/* Level 4 */
box-shadow: 0 6px 10px 4px rgba(0,0,0,0.15), 0 2px 3px rgba(0,0,0,0.3);
/* Level 5 */
box-shadow: 0 8px 12px 6px rgba(0,0,0,0.15), 0 4px 4px rgba(0,0,0,0.3);
```
### Component Elevation Mapping
| Level | Components at Rest |
|-------|--------------------|
| 0 | App bar (flat), filled/tonal/outlined buttons, button groups, filled/outlined cards, carousel, chips, full-screen dialogs, icon buttons, lists, nav rail, segmented buttons, sliders, split buttons, tabs |
| 1 | Banners, modal bottom sheet, elevated button, elevated card, elevated chips, modal nav drawer, modal side sheet |
| 2 | App bar (scrolled), menus, nav bar, rich tooltips, toolbar |
| 3 | Date pickers, modal dialogs, extended FAB, FAB, FAB menu close button, search, time pickers |
**Hover/focus**: Most interactive components increase by 1 level on hover/focus (e.g., FAB goes from level 3 to level 4).
## Motion
### Spring-Based Motion (Expressive Update)
MD3 Expressive (May 2025) introduced spring-based motion physics for component animations. Springs create more natural, responsive motion:
- Springs have no fixed duration — they respond dynamically to input
- Two schemes: **standard** (utilitarian) and **expressive** (bouncy)
- **Jetpack Compose** exposes motion schemes / spring-oriented APIs in current Material3 (see `MotionScheme` and your BOM). **MDC-Android** may differ by version. **Web:** Material Web does not implement Expressive motion physics — use easing/duration or custom CSS/JS. **Flutter:** check your Flutter/Material version for parity.
### Easing and Duration (Transitions)
The easing/duration system is used for **transitions** (entering, exiting, shared-axis) and as a web fallback:
#### Easing Sets
**Emphasized** (recommended for most transitions — captures the MD3 style):
| Type | CSS Cubic-bezier | Use |
|------|-----------------|-----|
| Emphasized | `cubic-bezier(0.2, 0, 0, 1)` | Begin and end on screen |
| Emphasized Decelerate | `cubic-bezier(0.05, 0.7, 0.1, 1)` | Enter the screen |
| Emphasized Accelerate | `cubic-bezier(0.3, 0, 0.8, 0.15)` | Exit the screen |
**Standard** (for utility transitions, web fallback):
| Type | CSS Cubic-bezier | Use |
|------|-----------------|-----|
| Standard | `cubic-bezier(0.2, 0, 0, 1)` | Begin and end on screen |
| Standard Decelerate | `cubic-bezier(0, 0, 0, 1)` | Enter the screen |
| Standard Accelerate | `cubic-bezier(0.3, 0, 1, 1)` | Exit the screen |
#### Duration Scale
| Token | Value | Use |
|-------|-------|-----|
| Short 1 | 50ms | Micro-interactions |
| Short 2 | 100ms | Small transitions |
| Short 3 | 150ms | Small transitions |
| Short 4 | 200ms | Exit transitions |
| Medium 1 | 250ms | Medium transitions |
| Medium 2 | 300ms | Standard transitions |
| Medium 3 | 350ms | Medium transitions |
| Medium 4 | 400ms | Enter transitions |
| Long 1 | 450ms | Large transitions |
| Long 2 | 500ms | Large, emphasized transitions |
| Long 3 | 550ms | Complex transitions |
| Long 4 | 600ms | Complex transitions |
| Extra Long 1 | 700ms | Page transitions |
| Extra Long 2 | 800ms | Page transitions |
| Extra Long 3 | 900ms | Complex page transitions |
| Extra Long 4 | 1000ms | Complex page transitions |
#### Suggested Pairings
| Transition | Easing | Duration |
|-----------|--------|----------|
| Element stays on screen | Emphasized | 500ms |
| Element enters screen | Emphasized Decelerate | 400ms |
| Element exits permanently | Emphasized Accelerate | 200ms |
| Element exits temporarily | Emphasized | 300ms |
| Small utility transition | Standard | 300ms |
### CSS Implementation
```css
:root {
/* Easing */
--md-sys-motion-easing-emphasized: cubic-bezier(0.2, 0, 0, 1);
--md-sys-motion-easing-emphasized-decelerate: cubic-bezier(0.05, 0.7, 0.1, 1);
--md-sys-motion-easing-emphasized-accelerate: cubic-bezier(0.3, 0, 0.8, 0.15);
--md-sys-motion-easing-standard: cubic-bezier(0.2, 0, 0, 1);
--md-sys-motion-easing-standard-decelerate: cubic-bezier(0, 0, 0, 1);
--md-sys-motion-easing-standard-accelerate: cubic-bezier(0.3, 0, 1, 1);
/* Duration */
--md-sys-motion-duration-short1: 50ms;
--md-sys-motion-duration-short2: 100ms;
--md-sys-motion-duration-short3: 150ms;
--md-sys-motion-duration-short4: 200ms;
--md-sys-motion-duration-medium1: 250ms;
--md-sys-motion-duration-medium2: 300ms;
--md-sys-motion-duration-medium3: 350ms;
--md-sys-motion-duration-medium4: 400ms;
--md-sys-motion-duration-long1: 450ms;
--md-sys-motion-duration-long2: 500ms;
--md-sys-motion-duration-long3: 550ms;
--md-sys-motion-duration-long4: 600ms;
--md-sys-motion-duration-extra-long1: 700ms;
--md-sys-motion-duration-extra-long2: 800ms;
--md-sys-motion-duration-extra-long3: 900ms;
--md-sys-motion-duration-extra-long4: 1000ms;
}
/* Example: dialog enter */
.md3-dialog-enter {
animation: dialog-enter var(--md-sys-motion-duration-medium4)
var(--md-sys-motion-easing-emphasized-decelerate);
}
@keyframes dialog-enter {
from { opacity: 0; transform: scale(0.8); }
to { opacity: 1; transform: scale(1); }
}
/* Example: fade out */
.md3-fade-out {
animation: fade-out var(--md-sys-motion-duration-short4)
var(--md-sys-motion-easing-emphasized-accelerate);
}
@keyframes fade-out {
from { opacity: 1; }
to { opacity: 0; }
}
```