CSS is a stylesheet language used to specify the presentation, styling, and visual layout of HTML and XML documents across media types.
CSS (Cascading Style Sheets) is a declarative stylesheet language standardized by the World Wide Web Consortium (W3C). First proposed by Håkon Wium Lie in 1994, CSS controls the visual layout, typography, colors, animations, and responsive adaptations of HTML and XML documents across desktops, mobile devices, print media, and screen readers. Through its core principles—the Cascade, Specificity, and the Box Model—CSS governs modern web UI design and user experience.
Format, beautify, and validate stylesheets with our CSS Formatter tool or experiment with keyframes using our CSS Animation Generator.
| Specification | Details |
|---|---|
| Standard Organization | World Wide Web Consortium (W3C) |
| MIME Media Type | text/css |
| File Extension | .css |
| Modern Standards Mode | CSS Snapshot / Living Standard Modules |
| Layout Engines | Flexbox (1D), CSS Grid (2D), Multi-column, Subgrid |
| Modern Capabilities | CSS Custom Properties (Variables), Container Queries, :has() relational selector, Cascade Layers (@layer) |
The Cascade resolves conflicts when multiple style rules target the exact same HTML element. The evaluation order proceeds as follows:
@layer Rules < Inline Styles < !important Author Rules < !important User-Agent Styles.(ID, Class/Attribute/Pseudo-class, Element/Pseudo-element).Specificity Weight Matrix:
(1, 0, 0) -> #sidebar-nav (Highest)
(0, 2, 1) -> ul.menu-list > .active
(0, 0, 1) -> p (Lowest)
Every element rendered in the browser viewport is treated as a rectangular box comprising four concentric layers:
/* Recommended universal box model reset */
*, *::before, *::after {
box-sizing: border-box; /* Width & height include padding and border */
}
/* Define design tokens via CSS Custom Properties */
:root {
--font-primary: 'Inter', system-ui, sans-serif;
--color-brand: #0284c7;
--color-surface: #ffffff;
--color-text: #0f172a;
--radius-lg: 12px;
--space-md: 1.5rem;
}
@media (prefers-color-scheme: dark) {
:root {
--color-surface: #0f172a;
--color-text: #f8fafc;
}
}
/* Fluid responsive grid without media queries */
.card-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: var(--space-md);
padding: var(--space-md);
}
.feature-card {
background-color: var(--color-surface);
color: var(--color-text);
border-radius: var(--radius-lg);
padding: 1.5rem;
box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.feature-card:hover {
transform: translateY(-4px);
}
!important for Routine Styling: Resorting to !important breaks the natural specificity cascade and creates maintenance bottlenecks. Instead, manage architecture using modern @layer declarations.aspect-ratio or width/height attributes on images and video wrappers to avoid Cumulative Layout Shift penalties during page load.transform: translate3d(...) or opacity) rather than geometric layout triggers (top, left, margin, width), allowing the browser to offload computations to the GPU compositor thread.Flexbox is designed for 1-dimensional layouts (arranging elements in either a row or a column, like toolbars or navigation lists). CSS Grid is a 2-dimensional system designed to position elements simultaneously across both rows and columns (like complex dashboard layouts and editorial magazine grids).
While standard @media queries adapt layouts based on the overall browser viewport size, @container queries allow components to adapt styles dynamically based on the width or height of their parent container, enabling truly modular and reusable micro-components.
Paste raw CSS into our CSS Formatter to clean up indentation, or verify complex targeting logic using our interactive CSS Selector Tester.
Free, browser-based utilities to test, generate, and inspect CSS (Cascading Style Sheets) payloads directly.
Format, minify, and validate CSS with sorting and SCSS conversion.
Generate CSS keyframe animations with visual preview and easing functions.
Test CSS selectors against HTML with real-time matching and specificity analysis.