CSS Basics: Make Your Pages Look Good
Colours, Fonts and Text
In this lesson you will
- Write colours in several formats
- Change font family, size, weight and spacing
- Choose between px, rem and percentage units
Introduction
Colour and type do most of the work in making a page feel designed. CSS gives you several ways to write the same colour, and a handful of properties that control text.
Colour formats
All of these make the same kind of red. Use whichever you find easiest.
HTML · edit and run
colorsets the text colour.background-colorsets the background.- Add transparency with
rgb(0 0 0 / 50%)orrgba(0, 0, 0, 0.5).
Quick quiz
Which property changes the colour of the text?
Fonts
HTML · edit and run
font-familyis a list. The browser uses the first font it has, so end with a generic family such asseriforsans-serif.line-height: 1.6means 1.6 times the font size. Values between 1.4 and 1.7 read well.
Aligning and decorating
text-align:left,center,right.text-decoration:noneorunderline.text-transform:uppercase,lowercase,capitalize.letter-spacingadds space between letters.
HTML · edit and run
Units
pxis a fixed pixel size.remis relative to the page's base font size (usually 16px), so1.5remis 24px. It respects the reader's font settings, which makes it a good choice for text.%is relative to the parent.
Quick quiz
Why is rem often better than px for font sizes?
Try it yourself
Style this card: give the heading a hsl colour, set the paragraph to 1.1rem with line-height 1.7, and centre everything.
HTML · edit and run
Summary
- Colours: names, hex,
rgb()andhsl(). coloris text,background-coloris the background.font-family,font-size,font-weightandline-heightshape text.- Prefer
remfor text sizes.
Lesson complete
+20 XP
Nice work. Keep going while it is fresh.
Sources and further reading