HTML · The document layer

How do links and anchors work in HTML?

EasylinkshrefnavigationUpdated Oct 2026
Quiz this track

Short answer

A link is an a element with an href that navigates to another URL or a fragment. Write descriptive link text, use relative URLs for internal pages, and add rel=noopener when opening a new tab.

The href attribute is what makes an anchor a link. Without it, the a element is just inline text. The URL can be absolute, relative, a fragment such as #pricing, or a protocol such as mailto or tel.

html
<a href="/pricing">Pricing</a>
<a href="#faq">Skip to FAQ</a>
<a href="https://example.com" target="_blank" rel="noopener noreferrer">
  External guide
</a>
<a href="mailto:team@example.com">Email the team</a>

Writing good links

  • Link text should make sense on its own, such as 'View pricing plans'
  • Avoid 'click here' or 'read more' with no context
  • Use relative URLs for internal navigation so environments can change
  • Add rel=noopener to target=_blank as a safety measure
  • Do not use a link for an in-page action; use a button instead

Links are announced as links and activate with Enter. If the element triggers something like opening a menu or submitting a form, it should be a button, not an anchor with an empty href.

Fragment links jump to an element with a matching id. Keep ids unique and avoid relying on smooth scrolling for the core experience.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1When should you use target=_blank?
  2. 2Why is rel=noopener important?
  3. 3What is the difference between a fragment link and a normal link?
  4. 4Why is 'click here' poor link text?

Say it in the interview

A link is an anchor with an href, and it can point to an external URL, an internal path or a fragment on the same page. I write link text that describes the destination so it makes sense when read out of context. For external links that open a new tab, I add rel=noopener. If the control performs an action rather than navigating, it should be a button, not a link.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live HTML mock interview and get scored feedback on depth, clarity and confidence.