Navigation uses links; actions use buttons. CSS makes them look similar, but the underlying HTML must stay honest for keyboard and assistive tech.
Decision guide
- Go somewhere →
<a href="...">. - Do something here (submit, toggle, open menu) →
<button type="button">ortype="submit". - New tab →
target="_blank"plusrel="noopener noreferrer"for security.
Focus styles matter
Never remove focus outlines without replacing them. Use :focus-visible for keyboard-friendly rings that do not flash on mouse clicks.
Practice
- Tab through controls—notice
:focus-visiblestyles. - Change
.btn-primarypadding and border-radius together.
Important interview questions and answers
- Q: Why not use `` as a button?
A: It navigates (hash history), lacks button semantics, and behaves wrong for forms/dialogs. - Q: What does `rel="noopener"` do with `target="_blank"`?
A: Prevents the new page from accessing `window.opener` on your tab. - Q: How should focus be styled?
A: Visible, high-contrast outlines or rings—often via `:focus-visible`.