CSS
A style sheet language that controls how web pages look and how their elements are arranged. You use it to set colors, fonts, spacing, and layouts that adapt to different screen sizes.
What CSS does
CSS stands for Cascading Style Sheets. HTML gives a page its structure and meaning; CSS controls its presentation. A navigation menu can keep the same links and markup while appearing as a horizontal bar on a wide screen and a vertical list on a narrow one. The difference comes from styling, not from changing what the links mean.
How the browser chooses a style
A CSS rule has a selector and a block of declarations. In .notice { color: navy; }, .notice matches elements with the notice class, and color: navy sets their text color. Pages typically load rules from a .css file using <link rel="stylesheet">.
When multiple declarations set the same property on the same element, the browser uses the cascade to pick a winner. It considers factors such as where a declaration came from, whether it is marked !important, and which cascade layer it belongs to before comparing selector specificity. If the earlier criteria tie, the later declaration wins. Inheritance is different: a child can take its parent's color when it has no color of its own, but it doesn't inherit padding by default.
Example: a toolbar that wraps
.toolbar {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.5rem;
}
.toolbar button {
padding: 0.5rem 0.75rem;
}
The direct children of .toolbar become flex items. If there's not enough room for them on one line, they can wrap onto the next; no breakpoint is needed for this behavior. gap sets the space between items and between lines. The second rule adds space inside buttons anywhere in the toolbar, but leaves buttons elsewhere on the page alone.
Common uses and pitfalls
CSS handles page layout, typography, and visual states such as keyboard focus. Flexbox is useful for arranging items along a main axis. Use CSS Grid when items need to align to shared rows and columns. Media queries let you apply styles conditionally, for example based on viewport width or the user's reduced-motion preference.
A common mistake is expecting width to measure from one outer border edge to the other. With box-sizing: content-box, padding and borders add to the declared width. With border-box, they're included in it. Margins remain outside the box in either case. Another mistake is removing a focus outline without providing a visible replacement: keyboard users then have trouble telling which control is active.
What comes up in interviews
You might be asked why a declaration is crossed out in DevTools or why a component takes up more space than its declared width. Talk through what you'd check: whether the selector matches, which declaration wins, and what the computed styles and box model show. That gives a more useful answer than reaching for !important to make the symptom go away.