Web Development · Module 3 · Lesson 31 min read

Colours, Units & Typography

Colours

  • Named tomato, hex #4f46e5, rgb(79 70 229), with transparency rgb(0 0 0 / 50%), or hsl(243 75% 59%).
  • HSL (hue, saturation, lightness) makes it easy to create lighter and darker shades.

Units

UnitRelative toUse for
pxfixed pixelsborders, small details
remthe root font size (usually 16px)font sizes, spacing
emthe parent's font sizepadding that scales with text
%the parent elementwidths
vw / vhviewport width / heightfull-screen sections
frfree space in a gridgrid columns

💡 Use rem for font sizes so text respects the user's browser settings.

Typography

CSS
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

HTML
<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>