Give keyboard users the same image-card highlight

A blue focus ring around a linked image card with a visible Glass and concrete title.

Keep the title and link usable before adding a pointer effect. A single image card can show its caption from the start, then add the same decorative highlight when the link is hovered or reached with the keyboard.

Put the image and title in one link

Consider an example card for a small photographic collection. The link text is “Glass and concrete”. The image presents a preview and the title tells the visitor what’s on the next page. Put both inside the link and let the title remain visible on phones and in the keyboard sequence.

<a class="preview-card" href="/glass-and-concrete/">
  <span class="preview-card__image">
    <img src="glass-and-concrete.webp" alt="" width="720" height="480">
  </span>
  <span class="preview-card__title">Glass and concrete</span>
</a>

The empty alt value fits this example because the preview is decorative and the visible link text identifies the destination. If the image communicates information the title leaves out, describe that information in the appropriate text or alt value.

Use a decorative effect for both inputs

.preview-card {
  display: block;
  color: #172554;
}
.preview-card__image {
  display: block;
  border: 3px solid transparent;
}
.preview-card__image img {
  display: block;
  width: 100%;
  height: auto;
}
.preview-card:is(:hover, :focus-within) .preview-card__image {
  border-color: #2955ac;
}
.preview-card:focus-visible {
  outline: 3px solid #172554;
  outline-offset: 5px;
}

The border already takes up space, so changing its colour leaves the layout stable. The keyboard outline identifies the link separately from the picture effect. CSS Selectors defines :focus-within to match an element with focus or a focused descendant. With a single link it also works when the link itself has focus. CSS Selectors Level 4 on focus within.

Test the simplest version first

Tab once to reach the card and check the visible outline. Press Enter and confirm the promised page opens. Go back and move the pointer over the title and picture. On a touch screen, the first tap should follow the same link. Try a long caption at a narrow width and check that it stays readable without depending on the border.

This example changes a decorative border and keeps the caption visible. If you introduce an expanding panel over other content, work through how someone could hover the panel, keep it open long enough to use it and dismiss it where required. That introduces additional behaviours. W3C guidance for content shown on hover or focus.

For a family of cards, test the longest title and the most crowded row first. Give the link a visible label, keep the focus outline and add effects after the card already works as a link.