Skills / Web pages with HTML and CSS / Styling with CSS
Styling with CSS
Most of what makes a page look professional comes from four things in CSS: colour, type, spacing and the box model.
Colour. Set text colour with color and backgrounds with background-color. Colours can be names (navy), hex codes (#1a73e8) or rgb(26, 115, 232). Pick two or three colours and use them consistently.
Type. font-family chooses the font, font-size its size and line-height the space between lines. Body text is easiest to read at around 16 to 18 pixels with a line height of about 1.5.
The box model. The browser treats every element as a box made of four layers, from the inside out:
- Content: the text or image itself
- Padding: space inside the box, around the content
- Border: an optional line around the padding
- Margin: space outside the box, pushing other boxes away
So padding: 20px gives a button room to breathe inside, while margin-bottom: 24px keeps the next paragraph at a distance. Add box-sizing: border-box to all elements so a box's width includes its padding and border; layouts become far easier to predict.
Classes. To style only some elements, give them a class in the HTML (<p class="note">) and select it in CSS with a dot: .note { background-color: #fff6e0; }.
Good CSS is consistent: the same spacing steps (8, 16, 24, 32 pixels) and the same few colours everywhere.
The tutor gives hints, not finished answers. Log in to use it.