Part 5: Custom Properties, Responsive Design, and Modern CSS
Introduction
CSS Custom Properties (Variables)
Defining and Using
/* Define at :root β available everywhere */
:root {
--color-primary: #3b82f6;
--color-primary-dark: #2563eb;
--color-text: #1a202c;
--color-muted: #718096;
--color-bg: #ffffff;
--color-bg-subtle: #f7fafc;
--color-border: #e2e8f0;
--color-danger: #e53e3e;
--color-success: #38a169;
--font-body: system-ui, -apple-system, sans-serif;
--font-mono: 'JetBrains Mono', 'Fira Code', monospace;
--font-size-sm: 0.875rem;
--font-size-base: 1rem;
--font-size-lg: 1.125rem;
--font-size-xl: 1.25rem;
--font-size-2xl: 1.5rem;
--spacing-1: 0.25rem;
--spacing-2: 0.5rem;
--spacing-3: 0.75rem;
--spacing-4: 1rem;
--spacing-6: 1.5rem;
--spacing-8: 2rem;
--spacing-12: 3rem;
--radius-sm: 0.25rem;
--radius-md: 0.375rem;
--radius-lg: 0.5rem;
--radius-full: 9999px;
--shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
--shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}Fallback Values
Scoped Custom Properties
Dark Mode with Custom Properties
Responsive Design
Mobile-First Approach
My Breakpoint Tokens
Media Query Syntax
prefers-reduced-motion
prefers-reduced-motionContainer Queries
Modern CSS Features
CSS Nesting
:is() and :where()
:is() and :where():has() β The Parent Selector
:has() β The Parent Selectorclamp() for Fluid Typography
clamp() for Fluid Typographymin() and max()
min() and max()CSS Transitions
CSS Animations
scroll-behavior
scroll-behaviorscroll-margin-top
scroll-margin-topaccent-color
accent-colorcolor-scheme
color-schemeTypography
Utility Classes I Keep in Every Project
Summary
Feature
Key Point
Series Complete
Part
Topic
Last updated