CSS Tutorial
20 Topics- CSS Tutorial Overview
- CSS Introduction
- CSS Fundamentals
- CSS Selectors
- CSS Colors & Backgrounds
- CSS Text & Fonts
- CSS Box Model
- CSS Display & Positioning
- CSS Flexbox
- CSS Grid
- CSS Sizing & Layout
- CSS Lists & Tables
- CSS Transitions & Animations
- CSS Responsive Design
- CSS Advanced Styling
- CSS Functions
- CSS for Accessibility & Print
- CSS Architecture & Methodologies
- CSS Preprocessors & Tools
- CSS Modern & Experimental CSS
CSS Transitions, Transforms & Keyframe Animations
Create fluid, hardware-accelerated user interfaces with cubic-bezier curves, GPU compositing layers, and accessible motion controls.
1. The Three Rendering Pipelines: How to Avoid Animation Jank
Writing high-performance 60fps / 120fps animations requires knowing which browser rendering pipeline your CSS properties trigger:
| Pipeline Path | Triggering Properties | Performance Cost | Frame Drop Risk |
|---|---|---|---|
| Layout (Reflow) → Paint → Composite | width, height, top, left, margin, padding | Highest: CPU recalculates geometry for the element and all surrounding siblings. | Severe UI jank and stutter. |
| Paint (Repaint) → Composite | color, background-color, box-shadow, border-color | Moderate: Skips geometry calculation but forces CPU rasterization of pixels. | Moderate risk on low-end mobile devices. |
| Composite Only (GPU) | transform (translate, scale, rotate) and opacity | Minimal: Offloaded directly to the GPU on a separate composite texture layer. | Buttery smooth 60fps / 120fps motion guaranteed. |
CSS Example
/* High-performance GPU-accelerated hover effect */
.fast-card {
padding: 20px;
background: #ffffff;
border: 1px solid #e2e8f0;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
cursor: pointer;
/* Animate only transform and opacity */
transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.25s ease;
}
.fast-card:hover {
transform: translateY(-4px) scale(1.02);
box-shadow: 0 12px 20px rgba(0, 0, 0, 0.1);
}2. CSS Transitions & Timing Functions
A transition interpolates property values smoothly between two states (e.g. from default to :hover or :focus). It requires an explicit change of state to trigger.
transition-property: The CSS properties to animate (prefer specific property names overallfor performance).transition-duration: Time the transition takes (e.g.200ms,0.3s).transition-timing-function: The acceleration curve (ease,linear,ease-in,ease-out,cubic-bezier(x1, y1, x2, y2)).transition-delay: Pause before the transition starts.
transition: transform 300ms ease 100ms;, the first time value is always the duration, and the second time value is the delay.3. CSS Transforms (translate, rotate, scale, skew)
The transform property alters visual coordinates without disrupting surrounding document flow:
translate(x, y): Shifts position along horizontal and vertical axes (percentage values are relative to the element itself!).scale(x, y): Multiplies element dimensions (e.g.scale(1.1)increases size by 10%).rotate(deg): Rotates around thetransform-originpoint (defaults to element center).perspective(px): Establishes a 3D depth field for rotations along X and Y axes.
CSS Example
/* Transform combination example */
.transform-badge {
display: inline-block;
padding: 8px 16px;
background: #2563eb;
color: #ffffff;
border-radius: 6px;
font-weight: bold;
cursor: pointer;
transition: transform 0.3s ease;
}
.transform-badge:hover {
transform: rotate(5deg) scale(1.1);
}4. CSS Keyframe Animations (@keyframes)
Unlike transitions, @keyframes animations can run autonomously without requiring user interaction and can loop infinitely through complex multi-step choreographies.
The 8 Animation Properties:
animation-name: Corresponds to the identifier defined in@keyframes.animation-duration: Total duration per cycle (e.g.2s).animation-timing-function: Easing between keyframes.animation-delay: Initial wait time before first playback.animation-iteration-count: Repetitions (integer orinfinite).animation-direction:normal,reverse,alternate,alternate-reverse.animation-fill-mode:none,forwards(retains final frame),backwards,both.animation-play-state:runningorpaused(dynamically pause via CSS!).
CSS Example
/* Infinite pulsing radar beacon */
.beacon {
width: 24px;
height: 24px;
background-color: #10b981;
border-radius: 50%;
position: relative;
margin: 30px auto;
}
.beacon::after {
content: "";
position: absolute;
top: 0; left: 0; width: 100%; height: 100%;
border-radius: 50%;
background-color: #10b981;
animation: radar-pulse 2s cubic-bezier(0.25, 0.46, 0.45, 0.94) infinite;
}
@keyframes radar-pulse {
0% { transform: scale(1); opacity: 0.8; }
100% { transform: scale(3.5); opacity: 0; }
}5. Accessibility: prefers-reduced-motion
Rapid or excessive animations can trigger nausea, dizziness, and migraines in users with vestibular disorders. Always implement motion sensitivity overrides:
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
scroll-behavior: auto !important;
}
}6. Frequently Asked Questions (FAQ)
will-change: transform hints to the browser that an element will animate soon, allowing it to promote the element to a GPU composite layer in advance. Use it sparingly on specific heavy elements right before animation (e.g. on :hover). Applying will-change to dozens of elements wastes immense GPU video RAM and degrades mobile performance.transition: all instructs the browser engine to monitor every single CSS property for changes during every animation frame, including layout-triggering properties. Explicitly stating transition: transform 0.2s, opacity 0.2s allows the browser to optimize execution and ignore other properties.forwards applies the styles of the 100% keyframe after the animation ends. both applies backwards (applying the 0% keyframe styles during any animation-delay period) AND forwards (retaining the 100% styles after completion).Explore Related Tools
Hand-picked utilities and calculators related to this tool.
