Design system and theme project
Definition and purpose
A small design system connects semantic tokens, component rules and variants into a repeatable contract. This project combines theme selection with a responsive card and keyboard focus styling.
Theme tokens
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } @layer tokens, components; @layer tokens { .shell { --surface: white; --ink: #172033; --accent: navy; --space: 12px; } .shell[data-theme="dark"] { --surface: #172033; --ink: white; } } @layer components { .tile { box-sizing: border-box; display: grid; gap: var(--space); padding: var(--space); background: var(--surface); color: var(--ink); } .tile button { color: white; background: var(--accent); } .tile button:focus-visible { outline: 3px solid currentColor; outline-offset: -4px; } } </style> </head> <body> <section class="shell" data-theme="dark"> <article id="a" class="tile"> <h2>Account</h2> <button id="b" type="button">Details</button> </article> </section> </body></html>The dark shell changes inherited tokens while the card layout is unchanged. Edit data-theme to light to compare the palettes.
Syntax and mental model
Separate tokens from components with an explicit layer order. The theme changes semantic surface and ink tokens; the card consumes them rather than duplicating its layout. Use a grid and a narrow default with a media query for wide screens. Keep native button semantics and a visible focus outline. Document token names, supported variants, minimum space and the states that must be tested. The shell owns theme selection; components own their internal layout.
Responsive component
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } @layer tokens, components; @layer tokens { .shell { --surface: white; --ink: #172033; --accent: navy; --space: 12px; } .shell[data-theme="dark"] { --surface: #172033; --ink: white; } } @layer components { .tile { box-sizing: border-box; display: grid; gap: var(--space); padding: var(--space); background: var(--surface); color: var(--ink); } .tile button { color: white; background: var(--accent); } .tile button:focus-visible { outline: 3px solid currentColor; outline-offset: -4px; } } .tile { grid-template-columns: 1fr; } @media (min-width: 600px) { .tile { grid-template-columns: 1fr 1fr; } } </style> </head> <body> <section class="shell" data-theme="dark"> <article id="a" class="tile"> <h2>Account</h2> <button id="b" type="button">Details</button> </article> </section> </body></html>One column at narrow widths and two at wide widths, with a 12px gap.
Common mistakes
Do not test only the default theme or rely on color alone for focus. The sample palette is a starting point; check contrast and reflow for actual content, including RTL and enlarged text.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Layered stylesheets and component isolation. Next lesson: Keyboard focus and target size.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Design system and theme project — knowledge check
Five questions on design system and theme project.
Where should semantic theme values live?
What owns the internal card layout?
Which state needs a visible keyboard indicator?
Why declare a layer order?
What should the design-system contract document?