oblaat

a guide to conceiving, creating & publishing your own website

Basic styling: colours, fonts, sizing

Changing colours

Using CSS, you can change the colour of several things: most commonly, text and backgrounds. Everything that can be coloured with CSS accepts the same colour values in the same way.

To change the text and background colour of any element with CSS, the color and background-color properties are required. Those used to the Commonwealth spellings of words must to re-train their muscle memory.

body {
  color: white;
  background-color: black;
}

This is a pair of CSS rules applied to the body using defined colour names. It forces the text to be white on black, instead of the browser's default black on white.

When changing the colour of a document's background, always be sure to declare the text colour too, and vice versa. Your browser might have black text as the default, but somebody using dark mode settings might have white text by default—if you set the background to yellow, the text becomes unreadable.

CSS colour names

CSS has a total of 148 named colours, corresponding to defined hex values, that you can use in your code with no problem. Every browser understands the values red and royalblue and lightgoldenrodyellow.

A visual list of named colours is available on this website for reference.

Hex codes

xxx

Red, Green, Blue & Alpha

xxx

Changing the font used

Types of fonts

xxx

Fonts & their fallbacks

xxx

My website is in Comic Sans! Why is it unreadable on my phone?

Not everyone has Comic Sans!

Changing sizes

Text size

xxx

Line height

xxx

Element size

xxx

Text size

xxx