The <a> (anchor) tag is the browser's real navigation primitive: it gives links semantics, accessibility, and SEO behavior, and it avoids common button-vs-link pitfalls in production UIs.
Use this HTML interview question to rehearse a quick answer, common mistake, follow-up, and production pitfall.
What is the use of the <a> tag?Frontend interview answer
This HTML interview question tests whether you can explain HTML <a> tag: navigation semantics, accessibility, and common pitfalls, connect it to production trade-offs, and handle common follow-up questions.
- HTML <a> tag: navigation semantics, accessibility, and common pitfalls explanation without falling back to memorized docs wording
- Links and Anchor reasoning, edge cases, and production failure modes
- How you would answer the most likely HTML interview follow-up
Direct answer
Use <a> when the user is navigating to another URL, document, or fragment target. In production, the common mistake is treating anchors and buttons as interchangeable: <a> preserves link semantics, open-in-new-tab behavior, browser history, and SEO, while <button> is for in-page actions.
<a href="/pricing">See pricing</a>
Use case | Example |
|---|---|
Internal page |
|
External site |
|
Same-page section |
|
Email link |
|
Phone link |
|
Download |
|
Security and accessibility essentials
<a href="https://example.com" target="_blank" rel="noopener noreferrer">
Open docs in new tab
</a>
- Use descriptive text like
Read pricing details, notClick here. - When using
target="_blank", addrel="noopener noreferrer". - Use
<a>for navigation and<button>for in-page actions.
Practical scenario
In a dashboard sidebar, each menu item should be an anchor to support navigation semantics, open-in-new-tab behavior, and browser history correctly.
Common pitfalls
- Using fake links (
href="#") for button-like actions. - Missing
relwithtarget="_blank". - Non-descriptive labels that hurt screen reader users.
<a> is a route sign. href is the destination address. No address means no navigation.
<a>is for navigation.hrefdefines destination.- Good link text and secure new-tab usage make links professional and accessible.
Use this as one explanation rep, then continue with the HTML interview questions cluster or a guided prep path.