Cards & Lists — UI/UX

A card gathers everything about one thing, in the order image, title, description, action. Cards suit a few items chosen by looking, like three rooms. A list…

In a shopping app, the goods appear as boxes with big photos. Open your order history in the same app, and each order is a single short row. The two shapes are different, and that is on purpose.

A box that gathers everything about one thing (its photo, name, details and action) is a card. A run of rows for many things of the same kind, one row per thing, is a list. Mrs. Sri has both too, on paper. Her brochure shows each room on its own page with a big photo, because guests choose by looking. Her guestbook has one booking per line, because she reads it from top to bottom and compares the dates. Each page of the brochure is a card, and the guestbook is a list.

Card or list

Card List
Its content few items, and the picture matters many uniform items, a picture is optional
How it's read looked at one by one scanned and compared top to bottom
At Mist Homestay three rooms for a guest to choose from 16 December bookings on Mrs. Sri's dashboard

This is the height of each item on a phone 375px wide (measured in Chromium, WebKit and Firefox). The last column shows how many items are visible in a dashboard area 664px tall, the laptop's list area from the Density & Scale lesson. In the phone's 611px area, the result is the same: 1 room, 1 booking, and all 16 bookings.

Content One item Visible in a 664px dashboard area
A room as a card (4:3 photo, name, price, link) 443px 1 room
A booking as a card, with the room photo 379px + a 16px gap 664 ÷ 395 = 1.68, so 1 of 16
A booking as a list row (37px) 37px 664 ÷ 37 = 17.9, so all 16 bookings

For three rooms, one room per screen is exactly right, because a guest really does decide by looking at the photo. For 16 bookings, cards make Mrs. Sri scroll 16 times. A list shows them all at the same time.

Anatomy of a card

The anatomy of a card means its parts. Their order from top to bottom: image, title, description, action. The image catches the eye. The title gives a name. The description gives a reason to choose it. The action at the bottom (a link or a button) is the next step. Here is the HTML and CSS of the Terrace Room card:

<article class="card">
  <img class="card-image" src="terrace-room-800.jpg" width="1200" height="900" alt="">
  <div class="card-body">
    <h3><a class="card-link" href="/rooms/terrace">Terrace Room</a></h3>
    <p>Double bed, a window facing the mountains. 2 guests.</p>
    <p class="price">$35 / night</p>
    <a class="wa" href="https://wa.me/447700900123">Ask on WhatsApp</a>
  </div>
</article>

<style>
  .card { position: relative; border-radius: 0.75rem; border: 1px solid #E5E7EB; overflow: hidden; background: #fff; }
  .card-image { display: block; width: 100%; height: auto; }
  .card-body { padding: 1.25rem; }
</style>

In the exercise, the values are exactly these: <article class="card"> with border-radius: 0.75rem and overflow: hidden, and .card-body with padding: 1.25rem.

One click area per card

Mrs. Sri wants the whole Terrace Room card to be tappable. So she wraps the card in the link <a href="/rooms/terrace">. Inside the card there's a second link, "Ask on WhatsApp". Guess first: once the browser has read the HTML, where does that WhatsApp link end up?

Wrapping the whole card in an <a> looks handy, but HTML doesn't allow a link inside a link. We tested Mrs. Sri's code in Chromium, WebKit and Firefox. All three arranged the card's elements in the same way. Below is that arrangement. Each line is one element, written as the tag and then the class: a.wa is an <a> link with the class wa. An indented line sits inside the element above it. The wrapping link Mrs. Sri wrote has the class card-cover.

article.card
  a.card-cover          (the first link, holding only the photo)
    img.card-image
  div.card-body
    a.card-cover        (a copy of the first link: title, description, price)
      h3, p, p.price
    a.wa                (the WhatsApp link, on its own)

On meeting the second <a>, the parser (the part of the browser that reads HTML) closes the first link. Then the parser makes a copy of the first link for the title, description and price. So the answer to the guess: the WhatsApp link ends up outside the card link, and the card link is split in two.

There is another problem. A link's name (what a screen reader reads out) is taken from all the text inside it. A link that wraps the card holds all the card's text, so a screen reader reads "Terrace Room Double bed, a window facing the mountains. 2 guests. $35 / night".

The fix: put one short link on the title. Then make an invisible layer that belongs to that link, and stretch it over the whole card:

.card-link::after { content: ""; position: absolute; inset: 0; } /* a click layer as big as the card */
.card:focus-within { outline: 3px solid #1f2937; outline-offset: 2px; } /* the focus ring on the card */
.wa { position: relative; z-index: 1; } /* the second link stays above the layer */

A list for Mrs. Sri's dashboard

These are the first two rows of the booking list on Mrs. Sri's dashboard, with their CSS:

<ul class="list">
  <li class="list-item"><span><b>Rina</b> · Terrace Room, 1 Dec, 2 nights</span><b>$70</b></li>
  <li class="list-item"><span><b>Mr. Hadi</b> · Garden Room, 2 Dec, 1 night</span><b>$42.50</b></li>
</ul>

<style>
  .list-item { display: flex; justify-content: space-between; gap: 8px; padding: 8px 12px; font-size: 14px; line-height: 20px; border-bottom: 1px solid #e2e8f0; }
  .list-item:last-child { border-bottom: none; }
  .list-item > b { flex: none; white-space: nowrap; } /* the total must not break onto two lines */
</style>

⚠️ Cards that break without you noticing

TL;DR: A card gathers everything about one thing, in the order image, title, description, action. Cards suit a few items chosen by looking, like three rooms. A list shows many uniform items that get scanned and compared, like 16 bookings: 37px rows fit them all in a dashboard area 664px tall, while cards fit only 1. Wrap a card in <article>, the element for content that stands on its own. In the exercise: .card with border-radius: 0.75rem and overflow: hidden (it clips the photo to the rounded corners), then .card-body with padding: 1.25rem. Never put a link inside a link, because the browser splits it. To make the whole card tappable, give the card position: relative and put one link on the title. Then stretch an ::after { position: absolute; inset: 0 } layer (an extra element that CSS creates) from that link over the whole card. Lift a second link above that layer with position: relative; z-index: 1.

⚡ Card or list

Meaning: A card gathers everything about one thing, and suits a few items chosen by looking, like three rooms. A list shows many uniform items that get scanned and compared, like 16 bookings on Mrs. Sri's dashboard: 37px rows fit them all in an area 664px tall, cards only one.

⚡ Image, title, description, action

Write:

<article class="card">
  <img class="card-image" src="terrace-room-800.jpg" width="1200" height="900" alt="">
  <div class="card-body">
    <h3><a class="card-link" href="/rooms/terrace">Terrace Room</a></h3>
    <p>Double bed, a window facing the mountains. 2 guests.</p>
  </div>
</article>

<style>
  .card { position: relative; border-radius: 0.75rem; border: 1px solid #E5E7EB; overflow: hidden; background: #fff; }
  .card-body { padding: 1.25rem; }
</style>

Meaning: <article> is the element for content that stays whole when moved to another page, like this room card. border-radius rounds the card's corners, and overflow: hidden clips the photo to those corners. The padding goes on .card-body, not on .card, so the photo still touches the card's edges.

⚡ No link inside a link

Guess first: the whole card is wrapped in <a href="/rooms/terrace">, with an "Ask on WhatsApp" link inside. Where does the WhatsApp link end up?

Outside the card link, and the card link is split in two. HTML doesn't allow a link inside a link, so the browser closes the first link as soon as it meets the second <a>.

Meaning: Put one short link on the title. Then stretch an ::after layer (an extra element that CSS creates) over the whole card with position: absolute; inset: 0. The card needs position: relative, so the layer is measured from the card. Lift the second link above the layer with position: relative; z-index: 1.

What you will learn