Sphere
Log in Join
☆ 17

Is a button inside an anchor actually invalid HTML?

I have a card wrapped in an anchor with a button inside for saving. It works in browsers but a validator complains. What is the right pattern?

⚑ Report

3 replies

☆ 0
T Tom ·2026-10-29#1

Nested interactive elements are invalid and keyboards get confused. Make the card a div, put the anchor inside, and stretch it with a ::after pseudo-element.

⚑ Report
☆ 0
L Lena ·2026-10-29#2

Then how does the save button stay clickable above the stretched link?

⚑ Report
☆ 0
C Chloe ·2026-10-29#3

Give the button position: relative and z-index: 1. The stretched link covers the card, but the button sits above it in stacking order.

⚑ Report
Log in to reply.