What is CSS

Open any well-made website, strip out its CSS, and you are left with a tall column of black text on a white background: every heading, every paragraph, every link, stacked in order and completely unstyled. That plain column is your HTML. Everything that makes the page look designed, the colours, the spacing, the fonts, the columns and cards and navigation bars, is CSS. This chapter is about what that second language is and how it works alongside the first.
A page before and after CSS
CSS stands for Cascading Style Sheets. The part to hold onto is style: CSS is how you describe the appearance of a page. Your HTML says "this is a heading, this is a paragraph, this is a button". CSS then says "make the heading large and dark blue, give the button some padding and a rounded corner".
Think of HTML as the content of a room, the furniture and where it sits, and CSS as the paint, the lighting, and the arrangement. Same room, but one is bare and one is somewhere you'd want to be. You write CSS in separate rules that point at parts of your HTML and change how they look.
h1 {
color: navy;
font-size: 2rem;
}That is a single CSS rule. It finds every <h1> heading on the page and makes it navy and larger. The HTML stays exactly as it was; only its appearance changes.
How CSS points at your HTML
CSS only becomes useful when it can find the right parts of your page. It does that with a selector: the bit at the start of a rule that names what to style. In the rule above, h1 is the selector, and it means "every h1 heading".
You will usually target elements by giving them a class in your HTML and pointing at that class from CSS. A class is a label you choose:
<button class="buy-button">Buy now</button>.buy-button {
background-color: teal;
color: white;
}The .buy-button selector finds the element with that class and styles it. You will meet many kinds of selector later; classes are the ones you'll reach for most.
class="name" on an element in your HTML, then style .name in your CSS. Do not worry about the other kinds yet, classes will carry you a long way. What "cascading" means
The first word in Cascading Style Sheets is the one people skip, but it explains a lot. More than one rule can apply to the same element, and they can disagree. Maybe one rule says paragraphs are grey and another says this particular paragraph is black. The cascade is the set of rules the browser uses to decide which one wins.
Most of the time it comes down to one thing: if two rules are equally specific, the one written later wins. You do not need the full picture yet. Know that when a style does not show up the way you expect, it is usually because another rule beat it, not because CSS is broken.
Where CSS goes from here
CSS is a small language at its core, a selector and some property-value pairs, but it reaches a long way. Once you can target elements and set properties, the rest of this handbook is about the properties worth knowing and the systems built on top of them: the box model that controls spacing and size, then colour and type, and then the layout tools, flexbox and grid, that arrange a whole page.
The next chapter, how CSS works, gets concrete about the mechanics this one introduced: the three ways to attach CSS to a page, the exact anatomy of a rule, and how the cascade and inheritance decide what every element finally looks like.

