What is a CSS file?
CSS (Cascading Style Sheets) is a stylesheet language that controls the visual presentation of HTML documents. It defines colors, fonts, layouts, animations, and responsive design rules, separating content structure from visual styling. CSS was first proposed by Håkon Wium Lie in 1994 and has been maintained by the W3C ever since. The “cascading” in the name refers to how styles are applied in a priority order — inline styles override internal stylesheets, which override external files.
Every website you visit uses CSS. It is one of the three core web technologies alongside HTML (structure) and JavaScript (behavior).
How to open CSS files
- Any text editor — Notepad, TextEdit
- VS Code (Windows, macOS, Linux) — IntelliSense, live preview, Emmet shortcuts
- Sublime Text (Windows, macOS, Linux) — Syntax highlighting
- Any web browser — DevTools inspector (F12) lets you view and edit CSS live
- WebStorm (Windows, macOS, Linux) — Full IDE with CSS validation
Technical specifications
| Property | Value |
|---|---|
| Current Version | CSS3 (modular specification) |
| Encoding | UTF-8 |
| Type | Stylesheet language |
| Preprocessors | Sass, Less, Stylus |
| Standard | W3C Recommendation |
| MIME type | text/css |
Common use cases
- Web styling: Colors, fonts, spacing, borders, and background images
- Layout: Flexbox and CSS Grid for responsive page structure
- Responsive design:
@mediaqueries for mobile and desktop adaptation - Animations:
@keyframesandtransitionproperties for motion - Print styles:
@media printfor printer-friendly layouts - Frameworks: Bootstrap, Tailwind CSS, Bulma abstract common patterns into reusable classes
CSS selector types
CSS targets HTML elements through selectors:
/* Element selector */
h1 { color: #333; }
/* Class selector */
.button { padding: 8px 16px; }
/* ID selector */
#header { background: #fff; }
/* Pseudo-class */
a:hover { text-decoration: underline; }
/* Media query (responsive) */
@media (max-width: 768px) {
.sidebar { display: none; }
}
CSS preprocessors
Raw CSS has no variables, functions, or nesting. Preprocessors extend it with these features and compile to standard CSS:
- Sass / SCSS: Most popular; variables (
$color), nesting, mixins, inheritance - Less: Similar to Sass, used heavily by Bootstrap 3
- Stylus: More permissive syntax; less common
Modern CSS now natively supports custom properties (--variable-name) and nesting (in newer browsers), reducing the need for preprocessors.
Performance considerations
CSS is render-blocking — the browser must download and parse CSS before rendering. To minimize impact: place <link> tags in <head>, minify CSS for production, avoid deeply nested selectors, and use will-change and contain hints for animated elements. Critical CSS (the styles needed for above-the-fold content) can be inlined in HTML to accelerate first paint.
Developer tools
Browser DevTools (F12 in Chrome/Edge/Firefox) let you inspect any element’s computed styles, toggle properties on/off, and experiment with CSS changes live. The Computed tab shows which styles are actually applied after the cascade resolves all conflicts.