What is CSS?

CSS (Cascading Style Sheets) is the language that controls how HTML looks and is laid out: colors, typography, spacing, layout, responsiveness and animation. It works through rules, a selector plus declarations, and the "cascade" decides which rule wins when several target the same element.

Anatomy of a rule

.card { color: #0b1020; padding: 16px; }
  • Selector: .card, which elements to style.
  • Declaration: a property: value pair.

The "cascading" part

When rules conflict, the browser decides in this order:

  1. Origin and importance (user agent, user, author; !important flips the order).
  2. Cascade layers (@layer).
  3. Specificity (IDs > classes > elements).
  4. Source order (later wins).

Some properties (color, font) also inherit from parent to child.

What modern CSS can do

  • Layout: Flexbox, Grid, subgrid.
  • Responsiveness: media queries, container queries, clamp(), viewport units.
  • Logic: custom properties (variables), calc(), :has() (the parent selector), native nesting.
  • Motion: transitions, keyframe animations, view transitions, scroll-driven animations.

Why separate CSS from HTML

HTML describes meaning; CSS describes presentation. Keeping them apart lets one stylesheet restyle a whole site, keeps markup clean and improves caching.

Interview tip

Walk through how the cascade resolves conflicts; that is the concept most CSS bugs come from.

Code example

html
1<style>
2 :root { --brand: #2b4bff; }
3 body { font-family: system-ui; color: #0b1020; background: #fff8ec; }
4 .card {
5 max-width: 320px;
6 padding: 16px;
7 border: 2px solid currentColor;
8 border-radius: 12px;
9 box-shadow: 4px 4px 0 currentColor;
10 }
11 .card h2 { margin: 0 0 8px; color: var(--brand); }
12 .card:hover { transform: translate(-2px, -2px); transition: transform .15s; }
13 /* Responsive: stack padding tighter on narrow screens */
14 @media (max-width: 400px) { .card { padding: 10px; } }
15</style>
16<article class="card">
17 <h2>Hello CSS</h2>
18 <p>The same HTML, completely restyled by one stylesheet.</p>
19</article>

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the HTML & CSS set.

Open in study app