<a>

Term side of the Card.
Topic: Links
Unit title: <a>
Categories: Tag
Explanation side of the Card

Explanation: The element that creates a hyperlink to another page or resource. It can link to an external site, another page within the same site or a specific section within a page using the `href` attribute.

Browser compatibility:
  • The chrome browser supports this feature starting from version 1.
  • The edge browser supports this feature starting from version 12.
  • The firefox browser supports this feature starting from version 1.
  • The safari browser supports this feature starting from version 1.
Availability: 

Example

Wronghtml
<a href="#" onclick="openMenu()">
  Menu
</a>
Righthtml
<button type="button" onclick="openMenu()">
  Menu
</button>

An action that does not navigate is a <button>, which works with keyboard and screen readers by default.

Common mistakes

  • Using <a href='#'> with a click handler instead of a <button>.
  • Writing vague link text like 'here', which makes no sense out of context.

Key points

  • Every <a> used as a link has an href; actions without navigation use <button>.
  • Link text describes the target, not 'click here' or 'read more'.
  • Links that open a new tab say so in the text or accessible name.
  • Icon-only links have an accessible name from hidden text or aria-label.

Interview questions

Do I still need rel='noopener' with target='_blank'?

Modern browsers apply noopener by default for target='_blank'. Adding rel='noopener' is still harmless and covers older browsers.

Can I put block elements inside an a tag?

Yes, <a> can wrap blocks like <div> or headings, as long as it contains no other interactive content such as buttons or links.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy