Plan a page with reusable components
A real page is a collection of related components. Reusing tokens and layout patterns keeps a project coherent as it grows.
✓ What you will learn in this topic
- Explain the key idea: Plan content structure and reusable visual tokens before refining layout.
- Apply the concept: Repeated course cards share consistent spacing and wrap into the number of columns the available width supports.
- Avoid this common mistake:
Concept explanation
Begin by identifying page regions and repeated components. Give those components clear class names and keep the HTML reading order meaningful. Define a small set of color, type, spacing, and radius tokens before adding polish.
Choose Grid for repeated cards and Flexbox for a row of controls. Let the content flow naturally, then add a breakpoint only where the composition needs a different arrangement.
Syntax
A CSS rule has a selector followed by declarations. Each declaration is a property and a value; the braces group the declarations that apply to matching elements.
:root {
--space: 1rem;
--brand: #1d4ed8;
}
.demo {
display: grid;
gap: var(--space);
}Example 1: a small page element
Use this HTML as the target and place the CSS in a stylesheet linked to the page, or inside a <style> element while experimenting.
<main class="demo card-grid course-grid dashboard-panel course-card-list dashboard-grid card-layout"><h2>Learning card</h2><p>Clear styles make this information easier to scan.</p><nav class="site-nav"><a href="/learn">Courses</a></nav><label class="form-field"><span>Email</span><input type="email" aria-invalid="true"></label><article class="card course-card dashboard-card theme-dark"><span class="badge status">New</span><div class="course-card__image"></div><h2 class="course-card__title card__title">Course update</h2><p class="status">New lessons are available this week.</p><a href="/learn" aria-current="page">Read the details</a><div class="actions course-card__actions dashboard-panel__actions"><button type="button">View lessons</button><button type="button" disabled>Unavailable</button></div></article></main>:root {
--space: 1rem;
--brand: #1d4ed8;
}
.demo {
display: grid;
gap: var(--space);
}Expected result: Repeated course cards share consistent spacing and wrap into the number of columns the available width supports.
Example 2: a practical interface card
The same idea can style a reusable card on a course page. The class selector keeps the rule attached to this component rather than changing every element of that type.
<section class="demo card-grid course-grid dashboard-panel course-card-list dashboard-grid card-layout"><h2>Learning card</h2><p>Clear styles make this information easier to scan.</p><nav class="site-nav"><a href="/learn">Courses</a></nav><label class="form-field"><span>Email</span><input type="email" aria-invalid="true"></label><article class="card course-card dashboard-card theme-dark"><span class="badge status">New</span><div class="course-card__image"></div><h2 class="course-card__title card__title">Course update</h2><p class="status">New lessons are available this week.</p><a href="/learn" aria-current="page">Read the details</a><div class="actions course-card__actions dashboard-panel__actions"><button type="button">View lessons</button><button type="button" disabled>Unavailable</button></div></article></section>.course-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
gap: 1.25rem;
}
.course-card {
padding: 1.25rem;
border-radius: 1rem;
}Expected result: The course update reads as a distinct interface card, and its content follows the spacing, color, and layout choices in the rule.
Common mistake
Adding project styles as one-off overrides without a shared spacing, type, or component system.
Best practice
Start with semantic HTML, reusable tokens, and a simple layout; refine the design through viewport and keyboard testing.
Practice exercise
Build a responsive course landing page with navigation, a hero, a card grid, and a clear call to action. Apply it to the example above and inspect the result at a narrow and a wide viewport.
Section summary
- Plan content structure and reusable visual tokens before refining layout.
- Start with semantic HTML, reusable tokens, and a simple layout; refine the design through viewport and keyboard testing.
Knowledge check
Why identify repeated components before writing all the styles?
Reveal the explanation
A shared component rule avoids copy-pasted styling and makes updates predictable.
Finish the module lessons, then take the server-scored module quiz to check your understanding.
Practical example
css:root {
--space: 1rem;
--brand: #1d4ed8;
}
.demo {
display: grid;
gap: var(--space);
}
Expected result:
Repeated course cards share consistent spacing and wrap into the number of columns the available width supports.
Hands-on practice task
Build a responsive course landing page with navigation, a hero, a card grid, and a clear call to action.
In this section
Other lessons in Practical Responsive Website Projects
Broaden your knowledge
Related learning topics
HTML
Learn to structure accessible, meaningful web pages with a complete HTML course from first document to professional application patterns.
JavaScript
Build strong JavaScript foundations with browser examples, focused practice, beginner projects, and module quizzes.