- Home
- /
- Tutorials
- /
- CSS Tutorial
- /
- Responsive CSS Project
CSS Projects
Responsive CSS Project
Combine tokens, fluid sizing, Grid, Flexbox, container queries, theming, and reduced-motion handling in one page. The project combines tokens, layers, fluid sizing, Grid, container queries, theming, focus treatment, content stress tests, and user preferences.
This project puts the CSS tutorial together: a tutorial catalog with a header, filter controls and cards, built with layers, design tokens, Grid, container queries and a dark mode. The goal is a page that works at any width, with a keyboard, at 200% zoom and in both color schemes.
It draws on CSS Architecture for the structure, Container Queries for the cards, and the preference queries for reduced motion and color scheme.
The brief
Build a page that lists tutorials as cards, with a search box and a few filter buttons above them. It must work from a 320px phone to a wide monitor, follow the system's light or dark setting, and stay usable with only a keyboard.
The core stylesheet
Example
css
@layer reset, base, layout, components;
@layer base {
:root {
color-scheme: light dark;
--surface: light-dark(#fff, #111827);
--text: light-dark(#172033, #e5e7eb);
--accent: light-dark(#0369a1, #38bdf8);
}
body {
margin: 0;
font: 1rem/1.55 system-ui, sans-serif;
color: var(--text);
background: var(--surface);
}
:focus-visible {
outline: 3px solid var(--accent);
outline-offset: 3px;
}
}
@layer layout {
.catalog {
width: min(100% - 2rem, 75rem);
margin-inline: auto;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
gap: clamp(1rem, 2vw, 1.75rem);
}
.catalog__cell { container-type: inline-size; }
}
@layer components {
.card {
display: grid;
gap: 1rem;
padding: 1rem;
border: 1px solid color-mix(in oklch, currentColor, transparent 75%);
border-radius: 0.75rem;
}
@container (width >= 24rem) {
.card { grid-template-columns: 5rem 1fr; }
}
}The stylesheet is organized in layers, so resets lose to base styles and base styles lose to components without any specificity fights. Colors are tokens that switch automatically between light and dark with light-dark(). The page grid lays out the main areas, and each card measures its own width with a container query, so it rearranges itself in a narrow sidebar and in a wide column alike.
Check your work
- The page has no horizontal overflow at 320 CSS pixels.
- Text remains usable at 200% zoom.
- DOM order matches reading and keyboard order.
- Long titles and URLs wrap without breaking a card.
- Focus is visible in both color schemes.
- Motion is removed or reduced when requested.
- Images reserve space and use appropriate source sizes.
- The layout works with real content, not only equal-length placeholders.
Go through the checklist with real content, not placeholder text: long tutorial titles, short ones, missing images.
Project Feature Map
| Feature | Role in the project | Key syntax |
|---|---|---|
| Design tokens | Keep color, spacing, and type decisions consistent. | Custom properties |
| Page layout | Arrange major regions responsively. | Grid and Flexbox |
| Component response | Adapt cards to their available space. | @container |
| User preferences | Respect theme and motion settings. | Preference media queries |
Complete Example
Complete runnable example
html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Responsive CSS Project example</title>
<style>
* { box-sizing: border-box; }
body {
margin: 0;
padding: 2rem;
font-family: system-ui, sans-serif;
line-height: 1.5;
}
main { max-width: 70rem; margin-inline: auto; }
article, section, aside, form, .card, .panel {
padding: 1rem;
border: 1px solid #cbd5e1;
border-radius: 0.6rem;
}
@layer reset, base, layout, components;
@layer base {
:root {
color-scheme: light dark;
--surface: light-dark(#fff, #111827);
--text: light-dark(#172033, #e5e7eb);
--accent: light-dark(#0369a1, #38bdf8);
}
body {
margin: 0;
font: 1rem/1.55 system-ui, sans-serif;
color: var(--text);
background: var(--surface);
}
:focus-visible {
outline: 3px solid var(--accent);
outline-offset: 3px;
}
}
@layer layout {
.catalog {
width: min(100% - 2rem, 75rem);
margin-inline: auto;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
gap: clamp(1rem, 2vw, 1.75rem);
}
.catalog__cell { container-type: inline-size; }
}
@layer components {
.card {
display: grid;
gap: 1rem;
padding: 1rem;
border: 1px solid color-mix(in oklch, currentColor, transparent 75%);
border-radius: 0.75rem;
}
@container (width >= 24rem) {
.card { grid-template-columns: 5rem 1fr; }
}
}
</style>
</head>
<body>
<main><h1 style="width:min(100% - 2rem,75rem);margin-inline:auto">Tutorial catalog</h1><section class="catalog"><div class="catalog__cell"><article class="card"><div>CSS</div><section><h2>Cascade</h2><p>Learn why declarations win.</p><a href="#">Open lesson</a></section></article></div><div class="catalog__cell"><article class="card"><div>Grid</div><section><h2>Responsive Grid</h2><p>Build layouts around content.</p><a href="#">Open lesson</a></section></article></div></section></main>
</body>
</html>Browser Support
Feature | Chrome | Edge | Firefox | Safari |
|---|---|---|---|---|
| Container queries | 105 | 105 | 110 | 16 |
| color-mix() | 111 | 111 | 113 | 16.2 |
Versions show the first stable desktop release with unprefixed support. Data source: MDN Browser Compatibility Data 8.0.8. A partial-support note is included where it changes how the example behaves.
Make it yours
Once it works, change one thing at a time and see what breaks: add a fourth filter button, make the cards show more text, switch the accent color. A good layout survives these changes without new media queries.
Responsive CSS Project exercises
A row
Lay the list out in a row with flex.
The HTML your code works on
<ul class="list">
<li class="item">One</li>
<li class="item">Two</li>
<li class="item">Three</li>
</ul>Result
