· 2 min read · updated
Semantic design tokens
Created src/lib/styles/tokens.css with semantic color tokens (--brand, --text-1/2, --surface-1/2/3) mapped onto Open Props primitives.
What we did
- Created
src/lib/styles/tokens.csswith semantic color tokens (--brand,--text-1/2,--surface-1/2/3) mapped onto Open Props primitives. - Imported it once in
+layout.svelteand used the tokens onbodyandh1.
What I learned
- A token is a named design decision.
--gray-8is a value (primitive);--text-1says what it's for (semantic). - Components use semantic tokens and only
tokens.cssuses primitives. Then dark mode or a rebrand means editing one file. - Name tokens by role, not by appearance.
--light-graylies in dark mode;--surface-2doesn't. - Don't wrap every Open Props size in a token. Only real decisions that might change need a semantic name.
- Open Props color scales go from 0 (lightest) to 12 (darkest). Text and links on a light background usually need 7–9.
- WCAG AA contrast: 4.5:1 for normal text, 3:1 for large text and UI parts. DevTools shows the ratio in the color picker.
import 'file.css'is a side-effect import. CSS has no exports, soimport x from 'file.css'fails.- CSS has no
export. A custom property on:rootis available everywhere through inheritance.
Problems & fixes
[MISSING_EXPORT] "default" is not exported by tokens.css: I wroteimport tokens from …and wrapped the CSS inexport tokens { }. Fixed with a plainimport '…'and a bare:root { }block.- My first brand color,
--brown-0, was almost white and would have failed contrast. I changed it to--blue-9.
Links
Next
global.csswith cascade layers.