Chapter 33 of 33

Project: Build a Responsive Landing Page

Time to build something real. In this final project we create a complete, responsive landing page for an imaginary study website called StudyHub, using only HTML and CSS — no frameworks, no JavaScript.

Almost every chapter of this tutorial shows up somewhere: custom properties, the box model, Flexbox, Grid, media queries, clamp(), logical properties, nesting, :has(), transitions and BEM naming. As we go, each step points back to the chapter where the idea was explained.

The page has six parts:

┌────────────────────────────────────────────┐
│ HEADER   logo · nav links · button (sticky) │
├────────────────────────────────────────────┤
│ HERO     headline + text + buttons │ visual │
├────────────────────────────────────────────┤
│ FEATURES  4 cards in a responsive grid      │
├────────────────────────────────────────────┤
│ PRICING   3 plans, middle one highlighted   │
├────────────────────────────────────────────┤
│ FAQ       expandable questions              │
├────────────────────────────────────────────┤
│ CTA band  +  FOOTER                         │
└────────────────────────────────────────────┘

We tested the finished page in Chrome at 360px (phone), 768px (tablet) and 1280px (laptop) widths, in both light and dark mode. The descriptions and numbers below come from those tests.


Step 0: Plan Before You Code

Professional developers decide a few things before writing CSS:

  1. Mobile-first. Write the default styles for small screens, then add @media (width >= 768px) rules for bigger screens (see Responsive Design & Media Queries). Small-screen layouts are usually simpler — a single column — so this means less code.

  2. Design tokens. Colours, radius, shadow and spacing go into custom properties so they are defined once.

  3. Naming. Every component gets a BEM block name (hero, feature, plan, button...), as described in CSS Architecture & BEM.

  4. Layout tool per job. Flexbox for one-dimensional rows (header, button groups), Grid for two-dimensional or column layouts (hero, cards).

Create two files in the same folder: index.html and style.css.


Step 1: The HTML

Good CSS starts with good HTML. We use semantic elements — header, nav, main, section, article, footer — so screen readers and search engines understand the page, and the FAQ uses the native details/summary elements, which open and close without any JavaScript.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>StudyHub – Learn CS the smart way</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <header class="site-header">
    <div class="container site-header__inner">
      <a class="logo" href="#">Study<span class="logo__accent">Hub</span></a>
      <nav class="nav" aria-label="Main">
        <ul class="nav__list">
          <li><a class="nav__link" href="#features">Features</a></li>
          <li><a class="nav__link" href="#pricing">Pricing</a></li>
          <li><a class="nav__link" href="#faq">FAQ</a></li>
        </ul>
      </nav>
      <a class="button button--small" href="#pricing">Get started</a>
    </div>
  </header>

  <main>
    <section class="hero">
      <div class="container hero__inner">
        <div class="hero__content">
          <p class="hero__eyebrow">For B.Tech, BCA &amp; GATE aspirants</p>
          <h1 class="hero__title">Learn computer science the smart way</h1>
          <p class="hero__text">Clear notes, practice questions and mock tests for every core subject, in one place.</p>
          <div class="hero__actions">
            <a class="button" href="#pricing">Start learning free</a>
            <a class="button button--ghost" href="#features">See features</a>
          </div>
        </div>
        <div class="hero__visual" aria-hidden="true">
          <pre class="hero__code">int main() {
  learn("DSA");
  practice(100);
  return 0;
}</pre>
        </div>
      </div>
    </section>

    <section class="section" id="features">
      <div class="container">
        <h2 class="section__title">Everything you need to prepare</h2>
        <div class="features">
          <article class="feature">
            <h3 class="feature__title">Exam-ready notes</h3>
            <p class="feature__text">Short, accurate notes for DSA, OS, DBMS, CN and more.</p>
          </article>
          <article class="feature">
            <h3 class="feature__title">Practice questions</h3>
            <p class="feature__text">Hundreds of MCQs with step-by-step solutions.</p>
          </article>
          <article class="feature">
            <h3 class="feature__title">Mock tests</h3>
            <p class="feature__text">Timed tests in GATE format with detailed analysis.</p>
          </article>
          <article class="feature">
            <h3 class="feature__title">Placement prep</h3>
            <p class="feature__text">Interview questions and common coding patterns.</p>
          </article>
        </div>
      </div>
    </section>

    <section class="section section--alt" id="pricing">
      <div class="container">
        <h2 class="section__title">Simple pricing</h2>
        <div class="pricing">
          <article class="plan">
            <h3 class="plan__name">Free</h3>
            <p class="plan__price">₹0</p>
            <ul class="plan__features">
              <li>All tutorials</li>
              <li>50 practice questions</li>
            </ul>
            <a class="button button--ghost" href="#">Join free</a>
          </article>
          <article class="plan plan--popular">
            <p class="plan__badge">Most popular</p>
            <h3 class="plan__name">Pro</h3>
            <p class="plan__price">₹499<span class="plan__period">/year</span></p>
            <ul class="plan__features">
              <li>Everything in Free</li>
              <li>Unlimited questions</li>
              <li>20 mock tests</li>
            </ul>
            <a class="button" href="#">Go Pro</a>
          </article>
          <article class="plan">
            <h3 class="plan__name">Campus</h3>
            <p class="plan__price">₹199<span class="plan__period">/student</span></p>
            <ul class="plan__features">
              <li>Everything in Pro</li>
              <li>Class dashboard</li>
            </ul>
            <a class="button button--ghost" href="#">Contact us</a>
          </article>
        </div>
      </div>
    </section>

    <section class="section" id="faq">
      <div class="container container--narrow">
        <h2 class="section__title">Frequently asked questions</h2>
        <details class="faq">
          <summary class="faq__question">Is the free plan really free?</summary>
          <p class="faq__answer">Yes. All tutorials are free, no card needed.</p>
        </details>
        <details class="faq">
          <summary class="faq__question">Can I use it on my phone?</summary>
          <p class="faq__answer">Yes. Every page works on any screen size.</p>
        </details>
      </div>
    </section>

    <section class="cta">
      <div class="container cta__inner">
        <h2 class="cta__title">Ready to start?</h2>
        <a class="button button--light" href="#pricing">Create free account</a>
      </div>
    </section>
  </main>

  <footer class="site-footer">
    <div class="container">
      <p>© 2026 StudyHub. Made for students.</p>
    </div>
  </footer>
</body>
</html>

Notice a few details:

  • The viewport meta tag is essential; without it, phones render the page as a zoomed-out desktop page and your media queries never trigger.

  • The code box in the hero is purely decorative, so it has aria-hidden="true" to hide it from screen readers.

  • Every class follows BEM: plan is a block, plan__price is its element, plan--popular is a modifier. The buttons use a separate button block with modifiers, so they can be reused anywhere.


Step 2: Design Tokens

Open style.css and start with the custom properties (CSS Variables (Custom Properties)):

/* ===== 1. Design tokens ===== */
:root {
  --color-primary: #4f46e5;
  --color-primary-dark: #3730a3;
  --color-text: #1f2937;
  --color-muted: #6b7280;
  --color-bg: #ffffff;
  --color-bg-alt: #f3f4f6;
  --color-border: #e5e7eb;
  --radius: 12px;
  --shadow: 0 10px 25px rgb(0 0 0 / 0.08);
  --space-section: clamp(3rem, 8vw, 6rem);
  --font-body: system-ui, "Segoe UI", Roboto, sans-serif;
}

--space-section uses clamp() from Modern CSS: :has(), Nesting, clamp() & Logical Properties: sections get 48px of vertical padding on small phones (8vw of 360px is only 28.8px, so the 3rem floor wins), growing to a maximum of 96px on wide screens (8vw reaches 96px at a 1200px viewport).


Step 3: Reset and Base Styles

/* ===== 2. Reset & base ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
}

h1,
h2,
h3 {
  line-height: 1.2;
}

:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 3px;
}
  • box-sizing: border-box makes width include padding and border, so our card arithmetic stays simple (The Box Model).

  • line-height: 1.6 on body is inherited by all text; headings get a tighter 1.2.

  • :focus-visible gives keyboard users a clear outline without showing it on mouse clicks (Pseudo-classes & Pseudo-elements, Borders & Outlines). Never remove focus styles without replacing them.


Step 4: Layout Helpers

/* ===== 3. Layout helpers ===== */
.container {
  width: min(100% - 2rem, 70rem);
  margin-inline: auto;
}

.container--narrow {
  width: min(100% - 2rem, 45rem);
}

.section {
  padding-block: var(--space-section);
}

.section--alt {
  background: var(--color-bg-alt);
}

.section__title {
  margin-block: 0 2rem;
  font-size: clamp(1.75rem, 1.2rem + 2vw, 2.5rem);
  text-align: center;
}

The .container is the one-line responsive wrapper from the Modern CSS chapter. Let's calculate its width at our three test sizes (1rem = 16px, so 2rem = 32px and 70rem = 1120px):

Viewport100% − 2rem70remContainer width
360px phone328px1120px328px (16px gap on each side)
768px tablet736px1120px736px
1280px laptop1248px1120px1120px, centred by margin-inline: auto

.container--narrow is a BEM modifier for the FAQ, where long lines of text would be hard to read.


Step 5: The Button Component

/* ===== 4. Button ===== */
.button {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  border: 2px solid var(--color-primary);
  border-radius: 999px;
  background: var(--color-primary);
  color: white;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  transition: background-color 0.2s, transform 0.2s;

  &:hover {
    background: var(--color-primary-dark);
    transform: translateY(-2px);
  }
}

.button--small {
  padding: 0.4rem 1rem;
  font-size: 0.9rem;
}

.button--ghost {
  background: transparent;
  color: var(--color-primary);

  &:hover {
    color: white;
  }
}

.button--light {
  border-color: white;
  background: white;
  color: var(--color-primary);

  &:hover {
    background: #e0e7ff;
  }
}

Here we use native nesting for the hover states: &:hover inside .button means .button:hover. Remember that the & is required — a bare :hover would target hovered elements inside the button.

The hover effect combines a colour change with transform: translateY(-2px), and transition animates both over 0.2s (Transitions, Transforms). Animating transform is cheap for the browser because it doesn't trigger a new layout. border-radius: 999px is a common trick for fully rounded "pill" ends: any radius larger than half the height gives perfect semicircles.

Each modifier only lists what is different: button--ghost makes the background transparent and the text purple, keeping the 2px border from the base class as an outline.


Step 6: The Sticky Header

/* ===== 5. Header ===== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--color-bg);
  border-block-end: 1px solid var(--color-border);
}

.site-header__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding-block: 0.75rem;
}

.logo {
  font-size: 1.4rem;
  font-weight: 800;
  color: inherit;
  text-decoration: none;
}

.logo__accent {
  color: var(--color-primary);
}

.nav {
  order: 3;
  width: 100%;
}

.nav__list {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav__link {
  color: var(--color-muted);
  text-decoration: none;

  &:hover {
    color: var(--color-primary);
  }
}

@media (width >= 768px) {
  .nav {
    order: 0;
    width: auto;
  }
}

How it works:

  • position: sticky; top: 0; keeps the header at the top while scrolling (Positioning). It needs a background, or the content would show through it, and z-index: 10 keeps it above the page content (z-index & Stacking Context).

  • The inner container is a wrapping flex row with justify-content: space-between: logo on the left, button on the right.

  • On phones, .nav has order: 3 and width: 100%. Order 3 moves it after the button (which has the default order 0), and full width forces it onto its own line. Result: logo and "Get started" on the first row, the three links centred on a second row.

  • From 768px up, the media query resets order: 0 and width: auto, so the nav sits back in the middle of a single row: logo — links — button.

This is a simple, JavaScript-free responsive navigation that works well when there are only a few links. (Sites with many links usually switch to a "hamburger" menu, which needs a bit of JavaScript or a details element.)


Step 7: The Hero Section

/* ===== 6. Hero ===== */
.hero {
  padding-block: var(--space-section);
  background: linear-gradient(135deg, #eef2ff, var(--color-bg) 60%);
}

.hero__inner {
  display: grid;
  gap: 2.5rem;
  align-items: center;
}

.hero__eyebrow {
  margin: 0;
  color: var(--color-primary);
  font-weight: 600;
}

.hero__title {
  margin-block: 0.5rem 1rem;
  font-size: clamp(2rem, 1.2rem + 4vw, 3.75rem);
}

.hero__text {
  max-width: 40ch;
  margin-block: 0 2rem;
  color: var(--color-muted);
  font-size: 1.125rem;
}

.hero__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.hero__visual {
  padding: 2rem;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--color-primary), #9333ea);
  box-shadow: var(--shadow);
}

.hero__code {
  margin: 0;
  padding: 1.5rem;
  border-radius: 8px;
  background: #0f172a;
  color: #a5f3fc;
  font-size: clamp(0.85rem, 0.7rem + 0.5vw, 1rem);
  overflow-x: auto;
}

@media (width >= 768px) {
  .hero__inner {
    grid-template-columns: 1.2fr 1fr;
  }
}

Mobile: .hero__inner is a grid with a single implicit column, so the text and the code visual stack vertically with a 2.5rem gap.

768px and up: it becomes two columns, 1.2fr 1fr. At 1280px the container is 1120px; minus the 40px gap leaves 1080px to share in a 1.2 : 1 ratio:

1 fr = 1080 ÷ (1.2 + 1) = 1080 ÷ 2.2 ≈ 490.9px
text column   = 1.2 × 490.9 ≈ 589.1px
visual column = 1 × 490.9   ≈ 490.9px

Chrome's computed grid-template-columns was 589.078px 490.922px — matching the calculation. (CSS Grid explains fr.)

The headline uses fluid type: clamp(2rem, 1.2rem + 4vw, 3.75rem).

Viewport19.2px + 4vwResult
360px19.2 + 14.4 = 33.6px33.6px
768px19.2 + 30.72 = 49.92px49.92px
1280px19.2 + 51.2 = 70.4px60px (capped at 3.75rem)

The paragraph's max-width: 40ch keeps lines to roughly 40 characters, which is comfortable to read. The decorative pre gets overflow-x: auto (Overflow & Scrolling), so a long code line would scroll inside the box instead of widening the whole page on a small phone.


Step 8: The Features Grid

/* ===== 7. Features ===== */
.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(15rem, 100%), 1fr));
  gap: 1.5rem;
}

.feature {
  padding: 1.5rem;
  border: 1px solid var(--color-border);
  border-block-start: 4px solid var(--color-primary);
  border-radius: var(--radius);
}

.feature__title {
  margin-block: 0 0.5rem;
}

.feature__text {
  margin: 0;
  color: var(--color-muted);
}

The famous repeat(auto-fit, minmax(...)) pattern from Grid Layout Patterns creates as many columns as fit, each at least 15rem (240px) wide — without any media query. With a 24px gap, n columns need 240n + 24(n − 1) pixels:

ContainerColumns that fitEach column
328px (phone)1328px
736px (tablet)2 (3 would need 768px)(736 − 24) ÷ 2 = 356px
1120px (laptop)4 (5 would need 1296px)(1120 − 72) ÷ 4 = 262px

So the four cards show as a single column, then a 2 × 2 grid, then one row of four. The min(15rem, 100%) protects very narrow screens: if the container is narrower than 240px, the minimum becomes 100% instead of overflowing.

Each card has a 1px grey border but a thicker 4px primary-coloured top border, using the logical border-block-start. Because it comes after the border shorthand, it overrides just the top edge.


Step 9: The Pricing Cards

/* ===== 8. Pricing ===== */
.pricing {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(16rem, 100%), 1fr));
  gap: 2rem 1.5rem;
  align-items: start;
}

.plan {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 2rem;
  border-radius: var(--radius);
  background: var(--color-bg);
  box-shadow: var(--shadow);
}

.plan--popular {
  outline: 3px solid var(--color-primary);
}

.plan:has(.plan__badge) {
  padding-block-start: 2.75rem;
}

.plan__badge {
  position: absolute;
  inset-block-start: 0;
  inset-inline-start: 50%;
  translate: -50% -50%;
  margin: 0;
  padding: 0.25rem 1rem;
  border-radius: 999px;
  background: var(--color-primary);
  color: white;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.plan__name {
  margin: 0;
}

.plan__price {
  margin-block: 0.5rem 1rem;
  font-size: 2.5rem;
  font-weight: 800;
}

.plan__period {
  color: var(--color-muted);
  font-size: 1rem;
  font-weight: 400;
}

.plan__features {
  margin-block: 0 1.5rem;
  padding-inline-start: 1.25rem;
}

Several techniques meet here:

  • Same grid trick, bigger minimum (16rem): three plans side by side on a laptop, stacked on a phone. At 1280px the container could technically fit four 256px columns; because we used auto-fit (not auto-fill), the empty fourth track collapses to 0 and the three cards stretch to about 357px each.

  • Flex column inside each card, so the name, price, list and button stack neatly.

  • The "Most popular" badge is absolutely positioned relative to its card (position: relative on .plan). inset-block-start: 0 and inset-inline-start: 50% put its top-left corner at the top centre of the card; translate: -50% -50% then shifts it back by half its own width and height, so it sits exactly centred on the card's top edge.

  • :has(): .plan:has(.plan__badge) adds extra top padding only to cards that contain a badge, so the badge never overlaps the plan name. If we later move the badge to a different plan, the spacing follows automatically.

  • outline highlights the popular plan. Unlike a border, an outline takes no space in the box model, so the highlighted card stays exactly the same size as the others.

  • align-items: start lets each card be only as tall as its content; the Pro card is a bit taller because it lists three features.


/* ===== 9. FAQ ===== */
.faq {
  padding-block: 1rem;
  border-block-end: 1px solid var(--color-border);
}

.faq__question {
  font-weight: 600;
  cursor: pointer;
}

.faq__answer {
  margin-block: 0.75rem 0;
  color: var(--color-muted);
}
/* ===== 10. Call to action & footer ===== */
.cta {
  padding-block: var(--space-section);
  background: var(--color-primary);
  color: white;
}

.cta__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.cta__title {
  margin: 0;
  font-size: clamp(1.5rem, 1rem + 2vw, 2.25rem);
}

.site-footer {
  padding-block: 2rem;
  color: var(--color-muted);
  font-size: 0.9rem;
  text-align: center;
}

The details elements need very little styling: a divider line, a pointer cursor and bold questions. The browser draws the ▸ marker and handles opening and closing.

The call-to-action band is a flex row with space-between and flex-wrap: wrap: on wide screens the heading is on the left and the white button on the right; when there isn't enough room, the button wraps underneath.


Step 11: Dark Mode and Reduced Motion

/* ===== 11. Dark mode & reduced motion ===== */
@media (prefers-color-scheme: dark) {
  :root {
    --color-text: #e5e7eb;
    --color-muted: #9ca3af;
    --color-bg: #111827;
    --color-bg-alt: #1f2937;
    --color-border: #374151;
  }

  .hero {
    background: linear-gradient(135deg, #1e1b4b, var(--color-bg) 60%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .button {
    transition: none;
  }
}

This is where the design tokens pay off. In dark mode we only redefine the variables; every component that uses var(--color-bg) or var(--color-text) updates automatically. Only the hero gradient, which used a hard-coded light colour, needs its own override. In our dark-mode test the whole page switched to a deep navy background with light text, and the purple buttons and accents stayed the same.

prefers-reduced-motion respects users who have asked their operating system to reduce animation (for example because motion makes them dizzy). For them, the button hover effect still changes colour but without animation.


The Result

On a 1280px laptop: a white header with "StudyHub" on the left, three grey links in the middle and a purple pill button on the right. Below it, the hero shows a large dark headline on the left with two buttons, and a purple-to-violet gradient panel with a dark code box on the right. The features form one row of four cards with purple top edges. Pricing shows three white cards on a light grey band; the middle "Pro" card has a purple outline and a "Most popular" pill sitting on its top edge. Then the FAQ, a solid purple "Ready to start?" band with a white button, and a small grey footer.

On a 360px phone: the logo and "Get started" share the first row, with the three links centred below. The hero headline drops to 33.6px and the code panel moves below the text. Features and plans stack in a single column. No element is wider than the screen — Chrome reported no horizontal scrolling at any of the tested widths.


Testing Checklist

Before you call any page finished, check these:

  • Resize the browser slowly from 320px to 1600px wide. Nothing should overflow or overlap. In DevTools, the device toolbar (Ctrl + Shift + M in Chrome) lets you pick phone sizes.

  • Keyboard: press Tab through the page. Every link and button should show the focus outline, in a logical order.

  • Zoom to 200%. Text should grow and the layout should adapt, because we used rem rather than pure vw for font sizes.

  • Dark mode: switch your OS theme, or in Chrome DevTools use Rendering → "Emulate CSS media feature prefers-color-scheme".

  • Contrast: grey text on white must still be readable. DevTools shows the contrast ratio in the colour picker.

  • Validate: run the HTML through the W3C validator and check the DevTools console for errors.


Ideas to Extend the Project

  1. Add a testimonials section where cards become a horizontal scroll-snap carousel on phones (Overflow & Scrolling).

  2. Make the feature cards respond to their own width using container queries instead of the viewport (Container Queries).

  3. Add a fade-in animation for the hero with @keyframes, wrapped in prefers-reduced-motion: no-preference (Animations & Keyframes).

  4. Put the CSS into cascade layers — @layer reset, base, layout, components, utilities; — as shown in CSS Architecture & BEM.

  5. Add a manual light/dark toggle using a checkbox and :root:has(#theme-toggle:checked) to switch the variables.


Common Mistakes in Projects Like This

  • Forgetting the viewport meta tag — media queries then seem "not to work" on phones.

  • Fixed widths like width: 1200px on wrappers, causing horizontal scrolling on phones. Use min() or max-width.

  • Desktop-first CSS with many overrides for mobile, instead of simple mobile defaults plus a few min-width queries.

  • Hard-coded colours everywhere, which makes dark mode or a rebrand a huge search-and-replace job.

  • Removing the focus outline (outline: none) without an alternative, breaking keyboard navigation.

  • Absolutely positioned badges without a positioned parent — the badge then flies to the corner of the page instead of the card.

  • Images without width/height or aspect-ratio, causing the layout to jump as they load.


Interview / Exam Questions

1. What does "mobile-first" mean in CSS, and why is it preferred?

You write the base styles for small screens and add min-width (or width >=) media queries to enhance the layout for larger screens. Small-screen layouts are usually simpler (single column), so the base CSS stays small, and phones don't have to download and then override desktop rules.

2. With grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)) and a 24px gap, how many columns appear in a 1000px container, and how wide is each?

n columns need 240n + 24(n − 1) ≤ 1000 → 264n ≤ 1024 → n = 3. Width of each = (1000 − 2 × 24) ÷ 3 = 952 ÷ 3 ≈ 317.3px.

3. What is the difference between auto-fit and auto-fill when there are fewer items than tracks?

auto-fill keeps the empty tracks, so the items stay at their minimum-ish size and empty space remains at the end. auto-fit collapses empty tracks to 0, so the existing items stretch to fill the row. In our pricing section, auto-fit lets three cards fill a row that could hold four.

4. How is the "Most popular" badge centred on the card's top edge?

The card has position: relative; the badge has position: absolute with its top-left corner at top 0 and left 50% of the card. translate: -50% -50% moves the badge left by half its own width and up by half its own height, so its centre lands exactly on the midpoint of the card's top edge.

5. Why use outline instead of border to highlight the popular plan?

A border adds to the element's box size (and with border-box it eats into the content area), which would make the highlighted card look different in size from the others. An outline is drawn outside the box and takes no space in layout, so all cards keep identical dimensions.

6. How does redefining custom properties inside @media (prefers-color-scheme: dark) switch the whole page to dark mode?

All components read colours through var(--color-bg), var(--color-text) and so on. When the media query matches, the :root rule inside it gives these variables new values; since custom properties are inherited and resolved at computed-value time, every element using them picks up the new colours with no other changes.


Summary

Part of the pageMain techniquesChapters used
Tokens & dark modeCustom properties, prefers-color-schemeCSS Variables, Responsive Design
Containermin(), margin-inline: autoModern CSS, Margin & Padding
HeaderSticky positioning, flex-wrap, orderPositioning, Flexbox
HeroGrid with fr, clamp() fonts, gradientsCSS Grid, Backgrounds & Gradients
Features & pricingauto-fit + minmax(), absolute badge, :has()Grid Layout Patterns, Positioning, Modern CSS
ButtonsBEM modifiers, nesting, transitions, transformsCSS Architecture & BEM, Transitions
Accessibility:focus-visible, prefers-reduced-motion, semantic HTMLPseudo-classes, Animations

Congratulations — you have finished the CSS tutorial! You now know how the cascade decides which styles win, how boxes are sized and laid out with Flexbox and Grid, how to make pages responsive and accessible, and how to organise CSS so that it stays maintainable. The best next step is to practise: rebuild a few pages you like, one section at a time, and check every layout at several screen sizes.