Thuta Learning
CSS
ProjectsWeb DevelopmentBeginner

Mini Project

CSSLesson 3040 min

What you'll walk away with

  • Decide the content and semantic HTML before writing any styles
  • Collect colours and radii as custom-property tokens in :root
  • Add hover, :focus-visible and prefers-reduced-motion states to one component
  • Stress-test the project at 320px, with a long name and with the keyboard's Tab key

Explain it simply

Explain it simply

This lesson teaches very few new properties. Instead it combines selectors, the box model, colour, gradients, transitions, responsive widths and custom properties in one small project: a responsive profile card. It is simple enough for a beginner, yet genuinely useful on real websites.

Think of building a house with LEGO. You already know every brick, meaning every property. The hard part now is the order you put them together in, and whether the finished house survives a shake. You can reuse this pattern for team member cards, product cards, creator profiles and service cards.

Problem → Why → Solution

The problem: it matches the screenshot, not the users

To match the designer's desktop screenshot pixel for pixel, the card was written with width: 360px and height: 420px. With the short name in the screenshot it is perfect. On a 320px phone, though, the card is wider than the screen, and when a real name such as "Aung Kyaw Thu Htet Naing (Senior Frontend Engineer)" arrives, the text spills out below the 420px box.

The button's focus outline was also removed with outline: none because it looked ugly. A user who moves with the Tab key instead of a mouse can no longer tell whether the button is focused. A single screenshot cannot reveal any of these three problems.

.profile-card {
  width: 360px;   /* wider than a 320px phone */
  height: 420px;  /* long names spill out */
  padding: 24px;
}

.profile-button:focus {
  outline: none;  /* keyboard users lose their place */
}

What does "done" mean?

A screenshot shows one piece of content, one screen width and one mouse user. A component is only done when it survives changing content, many widths and different ways of interacting. That is why limits such as min() and min-height, and states such as :focus-visible, belong in the plan from the start.

Core concept: building a mini project in order

Even a small project goes more smoothly when it is built in the right order. Professional developers run through a short version of these five stages for every component they build.

1. Write the content and HTML first

A card is a self-contained piece of content, so it is an <article>. The name is an <h2>, the description a <p>, and the link goes somewhere, so it is an <a>. Read without any styles, it should still make sense. The avatar initials are pure decoration, so aria-hidden="true" hides them from screen readers.

2. Collect the design tokens

Colours and radii that repeat inside the card become custom properties in :root, such as --accent and --radius. Changing the theme later means editing one place.

3. Style the component with limits

Use width: min(100%, 360px) instead of width: 360px, give the card no height at all so the content decides, and add overflow-wrap: anywhere to the h2 for very long names.

4. Add the states

Add :hover for mice, :focus-visible for keyboards and prefers-reduced-motion for people who want less animation. :focus-visible shows the outline when focus arrives by keyboard, so mouse clicks do not trigger it.

5. Stress-test it

Test at 320px, with a long name, at 200% browser zoom, tabbing through with the keyboard and with the system's reduced-motion setting on. If anything breaks, go back to stage 3 or 4.

Why the order matters

Mixing HTML and styling at the same time makes it easy to forget what each div is for. Styling without tokens scatters colours everywhere. Adding states last lets you see at once whether outlines and transitions disturb the finished layout.

Mental model: build it, then shake it
  1. Content and semantic HTML
  2. Collect tokens in :root
  3. Style the component with limits
  4. Add hover, focus, motion states
  5. Test at 320px, long text, Tab

Every break you find in stage 5 is a win: you found it before a user did.

General pattern

css
:root { --token-name: value; }

.component {
  width: min(100%, var(--max-width));
  color: var(--token-name);
}

.component__action:hover { /* mouse feedback */ }
.component__action:focus-visible { outline: 3px solid var(--token-name); }

@media (prefers-reduced-motion: reduce) { /* remove motion */ }

Tokens are defined at the top, the component reads them with var() and has a fluid width, every interactive element has hover and focus-visible states, and motion can be switched off by a user setting.

The responsive profile card

This card is built with tokens, a focus state and reduced motion. To avoid needing an image file, the avatar is a circle with the initials "TL". For a real photo, use an <img> at 96px wide and tall with object-fit: cover, which fills the circle without squashing photos of other proportions. Run it and press Tab to reach the button.

profile-card.html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Profile card</title>
  <style>
    :root {
      --bg: #0f1117;
      --surface: #141824;
      --text: #eaf2ff;
      --muted: #a8b3c3;
      --accent: #77f5ff;
      --accent-2: #ff4dcd;
      --radius: 20px;
    }

    * { box-sizing: border-box; }

    body {
      margin: 0;
      padding: 16px;
      background: var(--bg);
      font-family: system-ui, sans-serif;
    }

    .profile-card {
      width: min(100%, 360px);
      margin: 40px auto;
      padding: 24px;
      text-align: center;
      color: var(--text);
      background: linear-gradient(135deg, var(--surface), var(--bg));
      border: 1px solid rgb(119 245 255 / 0.25);
      border-radius: var(--radius);
      box-shadow: 0 20px 50px rgb(0 0 0 / 0.35);
    }

    .avatar {
      display: grid;
      place-items: center;
      width: 96px;
      height: 96px;
      margin-inline: auto;
      border: 3px solid var(--accent);
      border-radius: 50%;
      font-size: 2rem;
      font-weight: 700;
    }

    .profile-card h2 { margin: 16px 0 8px; font-size: 1.5rem; overflow-wrap: anywhere; }
    .profile-card p { margin: 0; line-height: 1.7; color: var(--muted); }

    .profile-button {
      display: inline-block;
      margin-top: 16px;
      padding: 12px 18px;
      color: #041013;
      font-weight: 700;
      text-decoration: none;
      border-radius: 999px;
      background: linear-gradient(135deg, var(--accent), var(--accent-2));
      transition: transform 0.25s ease;
    }

    .profile-button:hover { transform: translateY(-2px); }

    .profile-button:focus-visible {
      outline: 3px solid var(--accent);
      outline-offset: 3px;
    }

    @media (prefers-reduced-motion: reduce) {
      .profile-button { transition: none; }
    }
  </style>
</head>
<body>
  <article class="profile-card">
    <div class="avatar" aria-hidden="true">TL</div>
    <h2>ThutaTech Learner</h2>
    <p>A future web creator learning CSS step by step.</p>
    <a href="#" class="profile-button">View Portfolio</a>
  </article>
</body>
</html>

Code breakdown

  1. Design tokens--accent: #77f5ff;

    The accent colour appears in three places: the avatar border, the button gradient and the focus outline. Changing the token updates all three at once.

  2. Fluid card widthwidth: min(100%, 360px);

    With 16px of body padding, a 320px screen leaves 288px, so the card is 288px wide; on wider screens it stops at 360px. There is no height, so more text simply makes the card taller.

  3. Centred initialsplace-items: center;

    display: grid with place-items: center puts "TL" in the exact middle of the circle, centring it vertically and horizontally with one declaration.

  4. Long-name safety.profile-card h2 { margin: 16px 0 8px; font-size: 1.5rem; overflow-wrap: anywhere; }

    Even a long username without spaces wraps inside the card instead of escaping it.

  5. Keyboard focus.profile-button:focus-visible {

    Instead of deleting the outline, it is redesigned in the brand colour. outline-offset moves it 3px away from the button's edge so it stays visible against the gradient.

  6. Reduced motion@media (prefers-reduced-motion: reduce) {

    For users who reduce motion, the transition is removed; the hover feedback itself remains.

You should see
A card sits centred on a dark navy background. At 1024px it is 360px wide, at 320px it is 288px, with no horizontal scroll. It shows the avatar circle, the name, the description and a gradient button; hovering lifts the button by 2px, and reaching it with Tab draws a cyan outline.

A definition-of-done checklist

Before a project goes into your portfolio, walk through this checklist item by item. Each check takes only minutes in the browser and catches problems that real users would hit.

  • No horizontal scrollbar at a width of 320px
  • A long name without spaces and a card with no description do not break the layout
  • At 200% browser zoom all text stays readable and nothing overlaps
  • Tab reaches every link and button, and focus is clearly visible
  • With reduced motion on, there are no transitions

In real projects

In real projects

Team pages, marketplace seller profiles and conference speaker lists all use this card pattern. In a real project you rarely show one card; you render twenty or fifty from CMS data, so unusual data always arrives: very long names, missing descriptions, no photo. Component libraries often keep each of these edge cases as its own story in a tool like Storybook and check them on every change.

Tokens grow in importance as the project grows. Changing the brand colour or adding a light theme means changing values in :root and nothing else. Many companies have an accessibility rule that forbids removing focus outlines, and reviewers question every outline: none they see.

Common mistakes

Common mistakes

Removing the focus outline

Writing outline: none (or outline: 0) without a replacement style leaves keyboard users lost on the page. If you dislike the default outline, do not delete it; redesign it with :focus-visible using your brand colour, thickness and offset.

Locking the card to a fixed height

Setting height: 420px to make cards match means the card with more text overflows. If you want equal heights, put the cards in a grid or a flex row; the items stretch to the same height by default.

Hard-coded colours scattered everywhere

With #77f5ff copied into five rules, the day the brand colour changes you will miss one. Any value that appears more than twice in a component deserves a token.

Mini challenge

Build a team section

Build a team section with three profile cards. One card has a very long name and another has a long description. The cards must wrap to fit the screen, and the buttons must line up along the bottom.

  • Keep tokens (--accent, --surface, --radius) in :root
  • .team is a repeat(auto-fit, minmax(240px, 1fr)) grid with width: min(100% - 32px, 1000px)
  • Each card is a flex column, and margin-top: auto pushes its button to the bottom
  • Buttons have a :focus-visible outline, and the long name wraps inside its card
/* Markup: section.team > article.member*3,
   each with h3, p and a.member__link */

:root {
  /* TODO: --accent, --surface, --text, --radius */
}

.team {
  /* TODO: auto-fit grid, gap, fluid width, centred */
}

.member {
  /* TODO: flex column, padding, surface background, radius */
}

.member h3 {
  /* TODO: long names must wrap */
}

.member__link {
  /* TODO: pinned to the bottom of the card */
}

/* TODO: :focus-visible outline for .member__link */

Expected: At 375px the three cards are stacked; at 1024px they sit in one row with equal heights and all three buttons aligned at the same height. The long name wraps inside its card and the page never scrolls sideways.

Show hint

Grid items in the same row already share a height. Make each card a flex column and give the link margin-top: auto: all the spare space goes above the link, so the buttons line up at the bottom. align-self: start stops the link from stretching to the card's full width.

Show solution
team.html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <style>
    :root {
      --accent: #77f5ff;
      --surface: #141824;
      --text: #eaf2ff;
      --radius: 16px;
    }

    * { box-sizing: border-box; }
    body { margin: 0; background: #0f1117; color: var(--text); font-family: system-ui; }

    .team {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
      gap: 24px;
      width: min(100% - 32px, 1000px);
      margin: 32px auto;
    }

    .member {
      display: flex;
      flex-direction: column;
      padding: 20px;
      background: var(--surface);
      border-radius: var(--radius);
    }

    .member h3 { margin: 0 0 8px; overflow-wrap: anywhere; }
    .member p { margin: 0 0 16px; color: #a8b3c3; }

    .member__link {
      margin-top: auto;
      align-self: start;
      padding: 10px 16px;
      border-radius: 999px;
      background: var(--accent);
      color: #041013;
      font-weight: 700;
      text-decoration: none;
    }

    .member__link:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
  </style>
</head>
<body>
  <section class="team">
    <article class="member">
      <h3>Su Su</h3>
      <p>Designer.</p>
      <a class="member__link" href="#">Profile</a>
    </article>
    <article class="member">
      <h3>AungKyawThuHtetNaingSeniorFrontendEngineer</h3>
      <p>Builds the design system.</p>
      <a class="member__link" href="#">Profile</a>
    </article>
    <article class="member">
      <h3>Hnin Wai</h3>
      <p>Writes the tutorials, reviews every lesson and answers questions daily.</p>
      <a class="member__link" href="#">Profile</a>
    </article>
  </section>
</body>
</html>

Quick quiz 1 / 3

With 16px of body padding and a 320px viewport, how wide is a card with width: min(100%, 360px)?

Quick quiz 2 / 3

Why choose :focus-visible instead of :focus for a button's focus style?

Quick quiz 3 / 3

What is the main benefit of keeping the card's colours as :root custom properties?

What to remember

  • Start from content and semantic HTML, then tokens, component, states and a stress test
  • Use width: min(100%, 360px) and let the content decide the height
  • Redesign the outline with :focus-visible instead of removing it, and respect reduced motion
  • Only call it done after testing at 320px, with a long name, at 200% zoom and with Tab

CSS reference — MDN Web Docs

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.

Mini Project | Thuta Learning