Skip to content
Tutorials Center
My learning

Topics

Lesson 127 of 139 ยท Projects

Project: Pricing Page

Build a responsive pricing page in seven stages with CSS Grid, subgrid, custom properties, a highlighted plan and a monthly or yearly switch made with :has().

A pricing page has one job: help someone compare a few options quickly and pick one. That makes it a great CSS exercise. The cards have to line up so that prices and features can be compared at a glance, one plan has to stand out without shouting, and the whole thing has to work just as well as a single column on a phone.

In this project you will build that page in seven stages. Every stage has an editor with the complete code so far, and each one links to the lessons it draws on. Two ideas carry most of the weight: custom properties, which let the highlighted plan re-theme itself with a handful of lines, and CSS Grid, with subgrid keeping every card's rows aligned.

The product is Inkwell, a fictional project tool for design studios, with three plans: Solo, Team and Studio.

Stage 1: The markup

The page is a <section> with a header and a list of plans. Each plan is an <article>, because it is a self-contained unit that would make sense on its own. Every card has the same five parts in the same order: name, description, price, feature list and button. That consistency matters later, when the grid lines the parts up across cards.

The Team plan has an extra plan--featured class and a "Most popular" badge. Its button also has a button--primary modifier, because it is the action we most want people to take.

Stage 1: markup

Already readable, already usable. Every stage from here on only changes how it looks.

Stage 2: Design tokens and the page header

Before styling any card, define the palette as custom properties on :root. There are only nine tokens: an accent color with a soft tint and a text color to put on top of it, two text colors, a line color, the card and page backgrounds, and a corner radius. Every rule you write from now on uses these names instead of raw values. That decision pays off in Stage 4.

The header is centered text with a deliberate hierarchy:

  • A small uppercase eyebrow in the accent color names the page.
  • The heading uses clamp() for a size that grows with the viewport but never drops below 1.75rem or passes 2.75rem (calc(), min(), max() and clamp()). text-wrap: balance evens out the line lengths so a two-line heading doesn't end with one lonely word (Wrapping, Overflow and Hyphens).
  • The lead paragraph is larger than body text but uses the muted color, so it supports the heading instead of competing with it.
Stage 2: tokens and header

max-width: 36rem on the header keeps the lines short enough to read comfortably, and margin: 0 auto 2.5rem centers the block and adds space below it (Margins).

Stage 3: The plan cards

Now each <article> becomes a card: white background, a light border, rounded corners and a faint shadow (Box Shadows). Each card is also a grid container with a 1rem gap. The rule .plan > * { margin: 0; } removes the default margins from every child, so the gap alone controls the spacing. One value, perfectly even rhythm.

A few details are worth a closer look:

  • The price. The amount is huge and heavy, with slightly negative letter-spacing to tighten large digits, and font-variant-numeric: tabular-nums so every digit is the same width. The "per month" text stays small and muted.
  • The check marks. Each feature gets a ::before pseudo-element with a check mark in a tinted circle. The list item is a flex container, and flex: none stops the circle from being squeezed when a feature wraps to two lines.
  • Accessible decoration. content: "โœ“" / ""; uses the alternative text syntax: the part after the slash is what screen readers announce, and an empty string means "say nothing". Browsers that don't understand the slash ignore the whole declaration and fall back to the plain content: "โœ“"; written just above it. That is the cascade working as a feature test.
  • Two button styles. The base .button is outlined in the accent color; .button--primary fills it in (Styling Buttons and Links).
Stage 3: plan cards

The cards stretch to the full width of the page for now. Layout comes in Stage 5; first, the Team plan needs to look special.

Here is the payoff from Stage 2. The featured card should be dark with light text, a lighter accent and a matching button. You could write a dozen override rules for its name, price, features and button. Instead, .plan--featured simply redefines the tokens.

Custom properties inherit, and every rule inside the card reads its colors through var(). Change --surface, --ink, --muted, --line, --accent, --accent-soft and --on-accent on this one element, and its background, text, divider, check marks and button all switch to the dark theme at once. No rule written in Stage 3 has to change. This is the core idea of Custom Properties: a component that styles itself from tokens can be re-themed just by setting new values on it.

The badge is taken out of the flow with position: absolute (Positioning). The card gets position: relative so that the badge is placed against it. top: 0 and left: 50% put the badge's top-left corner at the middle of the card's top edge, and translate: -50% -50% shifts it back by half its own width and height, so it ends up centered right on the edge.

Stage 4: the featured plan

Notice the card's color: var(--ink) and background: var(--surface) are declared on .plan, the same element that receives the new values. That works because var() always reads the value computed on the element itself, which already includes the featured overrides.

Try making Studio the highlighted plan instead: move plan--featured, the badge and button--primary to the third card. Not a single CSS change is needed.

Stage 5: The grid, with subgrid alignment

On small screens, the plans stack in a single column with a sensible max-width, centered with margin-inline: auto. The media query adds three equal columns from 50em (800 pixels) up, using repeat(3, 1fr) (Grid Tracks).

Three columns raise a new problem. The descriptions are different lengths, so the prices don't line up, and the feature lists are different lengths, so the buttons end up at different heights. Comparing plans gets harder.

Subgrid fixes it in two lines:

  • grid-row: span 5 makes each card cover five rows of the outer grid, one for each of its five parts.
  • grid-template-rows: subgrid tells the card to use those outer rows for its own children instead of creating its own.

Now all three names share one row, all three descriptions share the next, and so on. Each row is as tall as its tallest cell, so every price, every divider line and every button lines up across the cards. The outer gap: 1rem 1.5rem sets 1rem between those shared rows and 1.5rem between the columns.

Stage 5: grid and subgrid

The preview on this page is probably narrower than 800 pixels, so you will see the single column. To check the three-column version, temporarily change 50em to 20em. The cards will be cramped, but you can see the rows line up. Then try removing grid-template-rows: subgrid; and watch the buttons drift out of line.

The featured badge doesn't break the alignment, even though the Team card has six children. Absolutely positioned elements don't take part in grid layout, so only the five in-flow children use the subgrid rows.

Stage 6: A monthly and yearly switch with :has()

Many pricing pages let you switch between monthly and yearly billing. That sounds like a job for JavaScript, but CSS can now do it alone, thanks to the :has() selector.

The markup adds a <fieldset> with two radio buttons, and each price now appears twice, once with data-period="monthly" and once with data-period="yearly". The CSS logic is three rules:

  1. Hide every yearly price by default.
  2. When .pricing has a checked #billing-yearly radio inside it, hide the monthly prices.
  3. In that same situation, show the yearly ones.

:has() lets a rule on a parent react to the state of something inside it, which used to be impossible in CSS. The radios themselves are still real radio buttons, so the arrow keys move between them and screen readers announce the choice. See Checkboxes and Radios for the HTML side.

The switch is styled as a "segmented control". The radio circles are made invisible with opacity: 0 but stay focusable. The labels become pills, and label:has(:checked) gives the selected one a white background and a small shadow. For keyboard users, label:has(:focus-visible) draws the focus ring around the whole label, since the radio itself can't be seen (Styling Forms).

Stage 6: billing switch

Click Yearly and every price changes at once. The legend "Billing period" is hidden visually with the .visually-hidden class but still read by screen readers, so the group keeps its name (Accessible CSS).

:has() works in all current browsers. In an older browser that doesn't understand it, the two :has() rules are dropped, but the first rule still hides the yearly prices. The page shows monthly prices and the switch simply does nothing, which is a safe fallback. To hide the switch in those browsers as well, show it only inside @supports selector(:has(*)) { ... } (Feature Queries).

Stage 7: Interaction and polish

The final stage adds feedback and a final round of care.

Card lift. On hover, a card moves up 4 pixels with the translate property and its shadow grows. The transition lists translate and box-shadow by name, so nothing else animates by accident (Transitions).

Button hovers that adapt. The outlined buttons fill with the soft accent. For the primary button, the hover color is computed with color-mix(in oklch, var(--accent), var(--ink) 20%): the accent moved one fifth of the way toward the text color (Modern Color). On a light card that makes it darker; on the dark featured card, where --ink is white, the same rule makes it lighter. One rule, correct in both themes, because it is built from tokens.

Focus and motion. Buttons get a clear :focus-visible outline in the accent color, and the prefers-reduced-motion block removes the transitions and the lift for people who have asked for less movement (Motion and Performance).

Stage 7: the finished pricing page

color-mix() and the oklch color space are supported in all current browsers. Mixing in oklch keeps the result vivid; mixing in srgb tends to look a little gray in the middle.

Ideas to take it further

  • Add a comparison table under the cards with sticky column headers (Styling Tables).
  • Animate the price change with a short fade: give [data-period] a keyframe animation that runs whenever it becomes visible (Keyframe Animations).
  • Add a dark theme for the whole page by redefining the :root tokens in @media (prefers-color-scheme: dark) (Dark Mode). The featured card can keep its own tokens.
  • Switch the three columns to a container query, so the plans adapt to the space they are given instead of the viewport.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. How does the featured plan get its dark look without overriding the card's rules?

    Every rule reads its colors through var(). Setting new values for the tokens on .plan--featured changes all of them for that card and its descendants.
  2. 2. What do grid-row: span 5 and grid-template-rows: subgrid achieve together?

    The card spans five outer rows and passes them down to its children. Each shared row is as tall as its tallest cell, so matching parts align.
  3. 3. Which selector hides the monthly prices when the yearly radio is checked?

    The prices are not inside the radio, so a descendant selector starting from the radio can't reach them. :has() lets the shared ancestor react to the radio's state.
  4. 4. Why does content: "โœ“" / ""; have a plain content: "โœ“"; before it?

    An invalid declaration is dropped, so the earlier valid one stays in effect. Browsers that do understand the slash syntax use the later declaration, which hides the check mark from screen readers.
  5. 5. What does color-mix(in oklch, var(--accent), var(--ink) 20%) produce on the dark featured card?

    The mix moves the accent 20% toward the text color. The featured card redefines --ink as white, so the hover color becomes lighter there.

Summary

  • Give every card the same parts in the same order; it makes styling and alignment much easier.
  • Define colors as tokens on :root and read them everywhere with var().
  • A highlighted variant can re-theme itself by redefining tokens instead of overriding rules.
  • position: absolute plus translate: -50% -50% centers a badge on a card's edge.
  • Stack the cards on small screens; switch to repeat(3, 1fr) with a media query.
  • grid-row: span 5 with grid-template-rows: subgrid lines up the parts of every card.
  • :has() lets a parent react to a checked radio, enough for a monthly and yearly switch with no JavaScript.
  • color-mix() builds hover colors from tokens, so they work in every theme.

Next: Project: Responsive Restaurant Website.