Colours and units

Hex, rgb and hsl colours, plus when to use px, rem, % and viewport units.

Colours

CSS
.a { color: tomato; }             /* a named colour */
.b { color: #0f766e; }            /* hex: red, green, blue */
.c { color: rgb(15 118 110); }    /* the same teal as numbers */
.d { color: hsl(175 77% 26%); }   /* hue, saturation, lightness */
.e { color: rgb(15 118 110 / 50%); } /* half transparent */

Keep your brand colours in variables, so changing one line recolours the site.

CSS
:root {
  --brand: #047857;
}
.button {
  background: var(--brand);
}

Units

UnitUse it for
pxBorders and small fixed details
remFont sizes and spacing. It follows the reader's browser font setting
%A share of the parent, such as width: 50%
vw / vhA share of the screen width or height
frA share of the free space in a grid
โ† SelectorsThe box model โ†’