Interview Question

aria-label vs aria-labelledby?

aria-label writes a name; aria-labelledby reuses existing text.

💡 Concept ✅ Quick Revision 🌐 HTML

Answer

Both attributes give an accessible name, but the name comes from different places. • `aria-label` contains the name directly. • `aria-labelledby` points to visible text already on the page. • Choose the option whose defined semantics and behavior match the task.

💡 Simple Example

<h2 id="cart-title">Cart</h2><section aria-labelledby="cart-title"><p>Your cart is empty.</p></section>

⚡ Quick Revision

aria-label writes a name; aria-labelledby reuses existing text.