Units, Fonts, Text & Colour
Value types, absolute vs relative units, typography properties and modern colour.
CSS Units & Property Value Forms
| Absolute units | Relative units (2025 preferred) |
|---|---|
px pixelsin inchescm centimetresmm millimetrespt pointspc picas (12 points)
|
em — relative to parent fontrem — relative to root font% — percentage of parentvw / vh — viewport width/heightsvh — small viewport heightcqi — 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-seriffont-size— length value or keyword (1remrecommended)font-style—normal | italic | obliquefont-weight—normal | bold | 100–900font— 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
| Property | Values |
|---|---|
text-align | left | center | right | justify |
text-indent | Indents the first line, e.g. 2rem |
text-decoration | underline | overline | line-through | none |
text-transform | uppercase | lowercase | capitalize |
line-height | Spacing between lines, e.g. 1.6 recommended |
letter-spacing / word-spacing | Space 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
| Form | Example | Notes |
|---|---|---|
| Named | color: tomato; | 147 named colours in CSS |
Hex #RGB | color: #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: ;}