LEARNING OBJECTIVES ⌵
- Understand Google Material Design’s physical metaphor of tactile surfaces ("quantum paper") in 3D space.
- Master the 24-level elevation system (
z0throughz24) and its multi-layer shadow compositing physics. - Implement pure-CSS and MDC-driven Outlined Text Fields with dynamic floating label transitions.
- Map Material Design 3 (M3) color roles (
surface,on-surface,primary,on-primary) to HTML design tokens.
📖 The Mental Model & Story (Intuitive Foundation)
In 2014, Google design vice president Matías Duarte asked a fundamental question: "What is the screen made of?"
Before Material Design, web design was divided between extreme skeuomorphism (fake leather textures and wood grain buttons) and extreme flat design (featureless 2D colored rectangles where users couldn't tell what was clickable).
Google introduced the metaphor of Quantum Paper:
- Digital sheets of virtual paper that occupy physical space in a 3D environment ($X$, $Y$, and $Z$ axes).
- A virtual light source shines down from above, casting realistic ambient and key shadows.
- Higher elevation on the Z-axis means the element is "closer" to the user, casting a larger, softer shadow and naturally drawing visual focus.
+-------------------------------------------------------------------------------+
| THE 3D ELEVATION Z-AXIS METAPHOR |
| |
| [ LIGHT SOURCE ABOVE ] |
| \ |
| \ |
| v |
| Elevation z24: [ Modal Dialog / Alert Box ] ====> Huge, diffuse shadow |
| |
| Elevation z6: [ Floating Action Button (FAB) ]===> Medium, distinct shadow |
| |
| Elevation z2: [ Surface Card / Raised Box ] =====> Subtle contact shadow |
| |
| Elevation z0: [ Background Canvas Ground ] ====> Flat / No shadow |
+-------------------------------------------------------------------------------+
Technical Deep Dive & Specifications
The Elevation Shadow System
In standard CSS, a basic box shadow looks flat. Material Design composites two simultaneous shadow layers to mimic realistic global illumination:
- Umbra / Key Shadow: Cast by a directional light source, creating a sharp, darker contact edge.
- Penumbra / Ambient Shadow: Cast by ambient reflected light, creating a soft, diffuse halo.
/* Elevation z2 (Standard Card) */
box-shadow:
0px 3px 1px -2px rgba(0,0,0,0.2), /* Key shadow */
0px 2px 2px 0px rgba(0,0,0,0.14), /* Ambient shadow */
0px 1px 5px 0px rgba(0,0,0,0.12); /* Diffuse rim */
/* Elevation z8 (Hovered Card / Dropdown Menu) */
box-shadow:
0px 5px 5px -3px rgba(0,0,0,0.2),
0px 8px 10px 1px rgba(0,0,0,0.14),
0px 3px 14px 2px rgba(0,0,0,0.12);
Outlined Text Field & Floating Label Architecture
The Material Outlined Text Field is an intricate DOM pattern that animates the label from an in-field placeholder into the border notch when focused or populated:
+--- Label floats UP into border notch when focused or populated ---+
| |
v v
+-[ Email Address ]----------------------------------------------------+
| [email protected] |
+----------------------------------------------------------------------+
Pure-CSS Floating Label Mechanism
By combining the CSS :placeholder-shown pseudo-class with adjacent sibling combinators (+), we can achieve 100% pure-CSS floating labels without JavaScript:
<div class="material-field">
<input type="text" id="email" class="material-input" placeholder=" " required />
<label for="email" class="material-label">Email Address</label>
</div>
/* When input is focused OR has text (placeholder is NOT shown), float label up */
.material-input:focus + .material-label,
.material-input:not(:placeholder-shown) + .material-label {
transform: translateY(-1.5rem) scale(0.85);
color: var(--md-sys-color-primary, #6200ee);
}
Material Design 3 Design Token Roles
Material Design 3 (M3) standardizes on semantic color roles to guarantee accessible contrast ratios:
| Token Name | Semantic Role | Usage Example |
|---|---|---|
--md-sys-color-primary |
High-emphasis brand color | Filled buttons, active indicators |
--md-sys-color-on-primary |
High-contrast text on primary | Text inside filled buttons |
--md-sys-color-surface |
Neutral base surface color | Cards, sheets, dialog backgrounds |
--md-sys-color-on-surface |
Primary text on surface | Body typography, card titles |
--md-sys-color-surface-variant |
Slightly tinted secondary surface | Search bars, input borders |
--md-sys-color-outline |
Boundary line color | Outlined text field borders |
💻 Interactive Code Playground
Starter Code
Line-by-Line Code Breakdown
- Lines 13–24 (
:root { --md-sys-color-* }): Defines official Material 3 semantic token roles. Components reference these semantic roles rather than hardcoded hex colors. - Lines 39–51 (
.m3-card): Establishes a surface elevation plane. On hover, the dual-layer shadow transitions fromz1toz3, lifting the card toward the user. - Lines 61–74 (
.m3-input): Creates the outlined text box with a transparent background and custom border radius. - Lines 89–95 (
.m3-input:focus + .m3-label): The floating label animation. When the input receives focus or contains characters (:not(:placeholder-shown)), CSS scales and translates the label up into the border space. - Lines 123–139 (
.m3-fab): A fixed-position Floating Action Button resting at elevationz3on the Z-axis.
Expected Browser Render Output
+-----------------------------------------------------------------------------------+
| |
| +----------------------------------------+ |
| | (shield) | |
| | Cluster Authorization | |
| | Provide credentials to access nodes... | |
| | | |
| | +-[ Work Email Address ]-------------+ | |
| | | [email protected] | | |
| | +------------------------------------+ | |
| | | |
| | +------------------------------------+ | |
| | | Hardware Security PIN | | |
| | +------------------------------------+ | |
| | | |
| | [ (->) Authenticate ] | |
| +----------------------------------------+ |
| |
| +----+ |
| | (?) | [FAB] |
| +----+ |
+-----------------------------------------------------------------------------------+🏋️ Hands-On Exercise
🎯 The Challenge: Build an M3 Task Card with Elevation & Status Chips
Instructions:
- Create a Material Design surface card (
.m3-card) with elevationz1and a smooth hover transition to elevationz3. - Inside the card, build an outlined input field for "Task Summary" with a CSS floating label.
- Add a responsive priority chip selector using Material Design pill chips:
- "Critical" (
--md-sys-color-error) - "In Progress" (
--md-sys-color-primary) - "Backlog" (neutral surface variant)
- "Critical" (
- Add a filled Material button with an icon on the right side of the card footer.
🏁 Starter Code Sandbox
⚠️ Common Pitfalls
- Cumulative Layout Shift (CLS) on Floating Labels: If the floating label is not given
position: absolute;, focusing the input will push adjacent DOM content down, causing severe layout shifts that degrade Google Core Web Vitals. - Low Contrast on Tinted Elevation Surfaces: In dark themes, Material elevates surfaces by applying a lighter tint rather than a shadow. Ensure your
on-surfacetext remains WCAG AAA compliant against tinted surface backgrounds. - Missing
placeholder=" "in Pure-CSS Floating Labels: The CSS:not(:placeholder-shown)trick requires a single whitespace character in theplaceholderattribute to detect empty vs. populated states accurately.
💡 Pro Tips
- Map M3 Tokens to CSS Custom Properties: Structure your entire application around standard M3 tokens (
--md-sys-color-primary,--md-sys-color-surface). When switching between Light, Dark, and High-Contrast modes, you only need to swap the token variables on:root. - Use Material Symbols with Variable Font Axes: The modern Google Material Symbols font allows dynamic customization of optical size (
opsz), weight (wght), fill (FILL), and grade (GRAD) via CSSfont-variation-settings.
📌 Key Takeaways
- Material Design treats digital UI elements as tactile surfaces ("quantum paper") in a 3D Cartesian space ($X$, $Y$, $Z$).
- Elevation is expressed via dual-layer composite shadows (directional key shadow + diffuse ambient shadow).
- Floating labels can be engineered in pure CSS using
:focusand:not(:placeholder-shown)with sibling selectors. - Material 3 (M3) enforces semantic design token pairs (
primary/on-primary,surface/on-surface) to guarantee accessible contrast. - Floating Action Buttons (FABs) occupy high elevation (
z6) to signify the primary user workflow on the screen. - --