Colours, Units & Typography
Colours
- Named
tomato, hex#4f46e5,rgb(79 70 229), with transparencyrgb(0 0 0 / 50%), orhsl(243 75% 59%). - HSL (hue, saturation, lightness) makes it easy to create lighter and darker shades.
Units
| Unit | Relative to | Use for |
|---|---|---|
px | fixed pixels | borders, small details |
rem | the root font size (usually 16px) | font sizes, spacing |
em | the parent's font size | padding that scales with text |
% | the parent element | widths |
vw / vh | viewport width / height | full-screen sections |
fr | free space in a grid | grid columns |
💡 Use rem for font sizes so text respects the user's browser settings.
Typography
body {
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
font-size: 1rem;
line-height: 1.6;
color: #1f2937;
}
h1 { font-size: clamp(1.8rem, 5vw, 3rem); } /* grows with the screen, within limits */
- Always list fallback fonts.
- Web fonts: Google Fonts with
<link>, or self-host them. - Comfortable reading: a line height of 1.5–1.7 and lines of about 60–75 characters (
max-width: 65ch).
Backgrounds and shadows
background: linear-gradient(135deg, #6366f1, #22d3ee);
box-shadow: 0 4px 12px rgb(0 0 0 / 10%);
Example
<style>
body {
font-family: system-ui, sans-serif;
line-height: 1.6;
color: hsl(220 20% 20%);
max-width: 65ch;
margin: 2rem auto;
padding: 0 1rem;
}
h1 {
font-size: clamp(1.8rem, 6vw, 3rem);
background: linear-gradient(135deg, #6366f1, #22d3ee);
-webkit-background-clip: text;
color: transparent;
}
.badge {
display: inline-block;
padding: 0.25rem 0.75rem;
border-radius: 999px;
background: hsl(243 75% 95%);
color: hsl(243 75% 45%);
font-size: 0.875rem;
}
</style>
<h1>Beautiful type</h1>
<span class="badge">New</span>
<p>Readable text uses a comfortable line height and line length.</p>