Custom Properties, Lists & Spacing
CSS variables (design tokens), list styling and the classic spacing properties.
CSS Custom Properties (Variables)
- Defined with a
--prefix in:root { }for global scope. - Used with
var(--name, fallback)throughout the stylesheet. - Cascade and inherit like regular CSS properties, and can be changed per-component or per-theme.
- Enable design tokens — a single source of truth for spacing and colour.
- Fully dynamic — can be updated with JavaScript at runtime.
/* Design tokens in :root */
:root {
--color-primary: #00B4D8;
--color-bg: #001B2A;
--color-text: #CAD7EE;
--space-sm: 0.5rem;
--space-md: 1rem;
--radius: 0.5rem;
}
/* Use variables everywhere */
.button {
background: var(--color-primary);
padding: var(--space-sm) var(--space-md);
border-radius: var(--radius);
}
/* Dark mode override — change one place */
@media (prefers-color-scheme: dark) {
:root {
--color-bg: #060D14;
--color-text: #E8F4FD;
}
}
List Properties
list-style-type— bullet or numbering style. Unordered:disc(default),circle,square,none. Ordered:decimal,upper-roman,lower-alpha,upper-alpha.list-style-image— use a custom image as the bullet.list-style— shorthand combining type, position and image.- 2025: the
::markerpseudo-element styles bullets directly.
/* Unordered list bullets */
ul { list-style-type: square; }
/* Custom image bullet */
ul.special { list-style-image: url('dot.svg'); }
/* Ordered list types */
ol { list-style-type: upper-roman; }
/* Per-item override */
li.special { list-style-type: disc; }
/* 2025: style the bullet itself */
li::marker {
color: #FFB703;
font-size: 1.2em;
font-weight: bold;
content: "> ";
}
/* List shorthand */
ul { list-style: square inside url('img.png'); }
Text Alignment, Float & Margins
| Property | Purpose |
|---|---|
text-align | left | center | right | justify |
text-indent | Indents the first line of text |
float | Wraps text around an element (left | right | none) |
margin | Space outside the element border |
padding | Space between the border and the content |
/* Text alignment */
p { text-align: justify; }
h1 { text-align: center; }
.note { text-indent: 2rem; }
/* Float (legacy — for text wrapping around images) */
img { float: right; margin-left: 1rem; margin-bottom: 1rem; }
/* Clear floats */
.clearfix::after { content: ""; display: block; clear: both; }
/* Margin shorthand: top right bottom left */
.box { margin: 1rem 2rem; } /* top/bottom 1rem, left/right 2rem */
.box { margin-inline: auto; } /* centre block horizontally (2025) */
.box { padding-block: 1.5rem; } /* top + bottom padding */
2025: modern layout uses Flexbox and Grid — float is rarely needed now.
Activity — complete the code
Complete the code correctly to mark this lesson as complete automatically.
Complete the custom property usage and list styling.
:root {--primary: #2563eb;}.button {background: (--primary);}ul {list-style-type: ;}