HTML & CSS: Build a Responsive Reading Card

A small component is a useful place to learn layout. This exercise builds a reading card that stays readable on a phone and gives keyboard users a visible link to follow.

Start with the content

Create a file named index.html. The card has a topic, a heading, a short description, and one action. Use a real link for navigation; a styled paragraph would not give people the same keyboard behavior.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Reading card</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <main>
    <article class="card">
      <p class="topic">Web development</p>
      <h1>Your first useful component</h1>
      <p>Learn the building blocks, then make something small.</p>
      <a href="https://developer.mozilla.org/en-US/docs/Learn_web_development">Start learning</a>
    </article>
  </main>
</body>
</html>

Let the available space decide

Save this stylesheet next to the HTML file. The width uses a maximum instead of a fixed pixel value, so the card can shrink with the viewport. Padding creates space inside the card without requiring a second wrapper.

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, sans-serif;
  background: #edf2f7;
  color: #172b40;
}
main { padding: 48px 20px; }
.card {
  width: min(100%, 680px);
  margin-inline: auto;
  padding: clamp(24px, 5vw, 48px);
  background: white;
  border: 1px solid #ced9e4;
  border-radius: 12px;
}
h1 { font-size: clamp(28px, 5vw, 44px); line-height: 1.15; }
p { line-height: 1.7; }
.topic { color: #36526c; font-size: 14px; }
a { display: inline-block; padding-block: 12px; color: #075c9d; }
a:focus-visible { outline: 3px solid #075c9d; outline-offset: 5px; }

Check the result

Open the file in a browser, narrow the window, and press Tab. The card should fit without horizontal scrolling, the title should wrap naturally, and the link should show an outline when focused. Zoom to 200% and confirm that every word is still reachable.

Make it yours

Replace the heading with an article title from your own project. Add a second card only after the first one works at a narrow width. If you introduce an image, give it a meaningful alternative description when it adds information, and limit its width to the card. The next exercise is to filter a list of these cards with JavaScript.

Komentar