Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14
Chapter 3

Units, Fonts, Text & Colour

Value types, absolute vs relative units, typography properties and modern colour.


CSS Units & Property Value Forms

Absolute unitsRelative units (2025 preferred)
px pixels
in inches
cm centimetres
mm millimetres
pt points
pc picas (12 points)
em — relative to parent font
rem — relative to root font
% — percentage of parent
vw / vh — viewport width/height
svh — small viewport height
cqi — container query inline size

Other value types

  • Keywords: left, center, bold
  • Percentages: 50%, 100%
  • URL: url('image.png')
  • Colour: #RGB, rgb(), hsl(), oklch()
  • Variables: var(--custom)

Font Properties

  • font-family — list of fonts; the browser uses the first available, e.g. 'Segoe UI', Arial, sans-serif
  • font-size — length value or keyword (1rem recommended)
  • font-style — normal | italic | oblique
  • font-weight — normal | bold | 100–900
  • font — shorthand: style weight size family, e.g. font: italic bold 1rem 'Times New Roman'
p.big {
  font-size: 1.2rem;
  font-style: italic;
  font-family: 'Times New Roman', serif;
}

/* 2025: web font with display swap */
@font-face {
  font-family: 'My Font';
  src: url('font.woff2') format('woff2');
  font-display: swap;   /* prevents invisible text flash */
}

/* 2025: variable font — one file, full weight range */
body { font-family: 'Inter Variable', sans-serif; font-weight: 100 900; }

Text Properties

PropertyValues
text-alignleft | center | right | justify
text-indentIndents the first line, e.g. 2rem
text-decorationunderline | overline | line-through | none
text-transformuppercase | lowercase | capitalize
line-heightSpacing between lines, e.g. 1.6 recommended
letter-spacing / word-spacingSpace between characters / words
h2 { text-transform: uppercase; letter-spacing: 0.08em; }
a:hover { text-decoration: underline; }

/* 2025: smart line wrapping */
h1 { text-wrap: balance; }

/* 2025: truncate overflow with an ellipsis */
.card-title {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

Colours in CSS — 2025 Complete Guide

FormExampleNotes
Namedcolor: tomato;147 named colours in CSS
Hex #RGBcolor: #00B4D8;Most common — 16.7M colours
rgb()color: rgb(0 180 216);CSS4: no commas needed
hsl()color: hsl(194 100% 42%);Hue, Saturation, Lightness
oklch()color: oklch(0.55 0.15 220);Perceptual, wide-gamut P3 (2025)
color-mix()color: color-mix(in oklch, blue, red);Native colour blending (2025)

Activity — complete the code

Complete the code correctly to mark this lesson as complete automatically.

Complete the typography rule using a relative unit and a comfortable line height.

body {
font-family: 'Segoe UI', , sans-serif;
font-size: ;
line-height: ;
}