Values, Units, and Color
Choose flexible units, useful custom properties, and accessible color values.
CSS values can be absolute, relative, calculated, or derived from custom properties. rem supports user font preferences, percentages relate to a containing size, and modern functions such as clamp() express a bounded fluid value.
See the core pattern
Read this rule set from the outside in. Identify the inputs, the decision or transformation, and the result before changing it.
:root {
--space: clamp(1rem, 2vw, 2rem);
--text: #10231f;
--surface: oklch(97% 0.02 95);
}
.prose {
width: min(70ch, 100%);
padding: var(--space);
}Working rules
- Use rem for text and user-scalable spacing
- Use ch to control readable line length
- Measure foreground/background contrast rather than guessing
A common mistake
Viewport units alone can make text unusably small or huge. Bound fluid values with min(), max(), or clamp().
Guided practice
Create a fluid spacing value that never drops below 1rem or exceeds 3rem.
- Copy the example into the editable notebook below.
- Change one thing at a time and keep the program or rule valid.
- Explain the result in one sentence without relying on jargon.