/* Absolute */.box { width: 300px; } /* Fixed size *//* Font-relative */.text { font-size: 1.5rem; /* 24px if root is 16px */ padding: 1em; /* 24px (relative to own font-size) */ margin-bottom: 2rem; /* 32px (relative to root) */}/* Viewport units */.hero { height: 100vh; } /* Full viewport height */.banner { width: 100vw; } /* Full viewport width */.square { width: 50vmin; height: 50vmin; } /* Square *//* Font-based */input { width: 20ch; } /* ~20 characters wide *//* New viewport units for mobile */.mobile-hero { height: 100dvh; /* Dynamic - handles browser UI */}
Note: Use rem for typography and spacing (consistent,
accessible). Use em for component-scoped spacing. Use px for borders and shadows. Use dvh/dvw for mobile
viewport issues.
2. Color Values (hex, rgb, hsl, hwb, lab, lch, oklab)
Note: Use OKLCH for color manipulation (tints, shades, palettes)
- it's perceptually uniform. Use HSL for broad compatibility. Use RGB/Hex for simple colors.
3. CSS Custom Properties (Variables) and calc()
Feature
Syntax
Description
Example
Declaration
--name: value;
Define custom property with double dash
--primary-color: blue;
Usage
var(--name)
Reference custom property value
color: var(--primary-color);
Fallback
var(--name, fallback)
Provide fallback if variable undefined
color: var(--color, red);
Scope
:root, element
Variables inherit down DOM tree
:root { --size: 16px; }
calc()
calc(expression)
Mathematical calculations with mixed units
calc(100% - 20px)
Operators
+ - * /
Addition, subtraction, multiplication, division
calc(2 * 10px + 5%)
Example: CSS Custom Properties (Variables)
/* Global variables in :root */:root { --primary-color: #007acc; --secondary-color: #ff6600; --spacing-unit: 8px; --font-size-base: 16px; --border-radius: 4px;}/* Using variables */.button { background: var(--primary-color); padding: calc(var(--spacing-unit) * 2); border-radius: var(--border-radius); font-size: var(--font-size-base);}/* Scoped variables */.dark-theme { --primary-color: #4fc3f7; --bg-color: #1e1e1e;}/* Fallback values */.card { padding: var(--card-padding, 20px); /* 20px if not defined */}/* Nested var() */.element { --size: 100px; --half: calc(var(--size) / 2); width: var(--half); /* 50px */}
/* Define container */.container { container-type: inline-size; /* or: size (both dimensions) */ /* or: normal (default, no containment) */ container-name: card; /* Optional name */}/* Use container query units inside */.card-title { font-size: clamp(1rem, 5cqw, 2rem); /* Responsive to container width, not viewport */}.card-content { padding: 2cqw; /* 2% of container width */ gap: 1cqh; /* 1% of container height */}/* Named container queries */@container card (min-width: 400px) { .card-title { font-size: 3cqw; /* 3% of container named "card" */ }}/* Component entirely responsive to its container */.product-card { container-type: inline-size;}.product-title { font-size: clamp(0.875rem, 4cqi + 0.5rem, 1.5rem);}.product-image { width: 100%; height: 50cqh; /* 50% of container height */}
Note: Container query units enable component-scoped responsive
design. Use cqw/cqi for typography and spacing relative to container, not viewport.
Requires container-type on parent.
6. CSS4 Math Functions and Trigonometry NEW
Function
Syntax
Description
Returns
sin()
sin(angle)
Sine of angle
Number between -1 and 1
cos()
cos(angle)
Cosine of angle
Number between -1 and 1
tan()
tan(angle)
Tangent of angle
Number (unbounded)
asin()
asin(number)
Arc sine (inverse sine)
Angle in radians
acos()
acos(number)
Arc cosine (inverse cosine)
Angle in radians
atan()
atan(number)
Arc tangent (inverse tangent)
Angle in radians
atan2()
atan2(y, x)
Arc tangent of y/x in correct quadrant
Angle in radians
sqrt()
sqrt(number)
Square root
Non-negative number
pow()
pow(base, exponent)
Exponentiation (base^exponent)
Number
hypot()
hypot(x, y, ...)
Hypotenuse: √(x² + y² + ...)
Non-negative number
log()
log(value, base?)
Logarithm (default base e)
Number
exp()
exp(exponent)
e raised to power (e^x)
Number
Example: Trigonometric functions for circular layouts
Warning: Trigonometric functions use radians or degree units.
Use deg, rad, grad, or turn units. Performance impact on
complex calculations - use sparingly.
7. CSS Typed OM and Houdini Properties BETA
Feature
Syntax
Description
Use Case
@property
@property --name { }
Register custom property with type, syntax, inheritance
Note:@property enables smooth animation of custom
properties by defining their type. Without it, custom properties animate discretely (no interpolation). Required
for animating colors, numbers, angles, etc.
Value & Unit Best Practices
Use rem for typography and spacing (accessibility)
Use clamp() for fluid responsive typography
Use OKLCH/LCH for color manipulation and gradients
Use container query units for component-scoped responsive design
Register custom properties with @property for smooth animations
Use calc() with CSS variables for maintainable calculations
Use dvh/dvw instead of vh/vw on mobile for browser UI issues