HTML Links and Hyperlinks Tutorial

HTML Links and Hyperlinks Tutorial

HTML Links & Hyperlinks – Complete Guide | TipsInLearning
Home HTML Course HTML Links & Hyperlinks
Lesson 12 of 22

HTML Links & Hyperlinks

Master the <a> tag — the tag that makes the web a web. Learn href, target, link types, security attributes, and the best practices that make links accessible and SEO-friendly.

10 min read
Beginner
Navigation
The <a> tag is literally the tag that makes the web a web — without links, every page would be an isolated island with no way to move between them. Get href and target right, write descriptive text, and add rel="noopener noreferrer" on external links — those three habits put you ahead of most beginners from the start.
What You'll Learn
Create clickable links with the <a> tag
Use href and target attributes correctly
Link to pages, sections, email & phone
Security: rel="noopener noreferrer"
Write accessible, SEO-friendly link text
Style links with CSS hover states

What are HTML Links?

HTML links (hyperlinks) are connections between web pages created using the <a> (anchor) tag. When a user clicks a link, the browser navigates to the URL in the href attribute. Links can be text, images, buttons, or any other HTML element.

Every website on the internet is built on links. Navigation menus, "Read more" buttons, email links, download buttons — all of them are <a> tags with different href values.

Why "anchor"? The name comes from early web design where links literally "anchored" two documents together. This is also why links to sections on the same page (like #section-id) are called anchor links.

Link Syntax

Every link uses the same structure — an opening <a> tag with an href attribute, visible text or content between the tags, and a closing </a> tag:

HTML — basic link
<a href="https://tipsinlearning.blogspot.com">Visit TipsInLearning</a>

The href Attribute

The href (hypertext reference) attribute specifies the destination. Four types of values work:

Absolute URLs
Full address — https://example.com/page
Relative URLs
Local files — about.html, ../index.html
Anchor Links
Same-page sections — #section-id
Email & Phone
mailto: and tel: protocols
HTML — href types
<!-- Absolute URL (external site) -->
<a href="https://tipsinlearning.blogspot.com">Visit TipsInLearning</a>

<!-- Relative URL (same site) -->
<a href="about.html">About Page</a>

<!-- Anchor link (same page section) -->
<a href="#examples">Jump to Examples</a>

<!-- Email link -->
<a href="mailto:hello@tipsinlearning.com">Email Us</a>

<!-- Phone link (tappable on mobile) -->
<a href="tel:+911234567890">Call Us</a>

The target Attribute

The target attribute controls where the linked page opens. The default is the same tab. The two values you'll use most are:

_self
Same tab (default — no need to write it)
_blank
New tab — always add rel security attribute
HTML — target + security
<!-- Same tab (default — no attribute needed) -->
<a href="https://tipsinlearning.blogspot.com">Same Tab</a>

<!-- New tab — ALWAYS add rel for security -->
<a href="https://external-site.com"
   target="_blank"
   rel="noopener noreferrer">
  Open in New Tab (Secure)
</a>
Security rule: Any link with target="_blank" must also have rel="noopener noreferrer". Without it, the opened page can run JavaScript against your page through window.opener — a real vulnerability that bad actors exploit.

More Link Types

HTML — download, image as link, nav
<!-- Image wrapped in a link (whole image is clickable) -->
<a href="https://tipsinlearning.blogspot.com">
  <img src="logo.png" alt="TipsInLearning home page" />
</a>

<!-- Download link — triggers file download -->
<a href="cheatsheet.pdf" download>Download PDF Cheat Sheet</a>

<!-- Navigation menu -->
<nav>
  <a href="index.html">Home</a>
  <a href="courses.html">Courses</a>
  <a href="contact.html">Contact</a>
</nav>

Styling Links with CSS

By default, links are blue and underlined. CSS gives you complete control over every link state:

CSS — link states
/* Default state */
a { color: #7c3aed; text-decoration: underline; }

/* Hover */
a:hover { color: #e85d04; text-decoration: none; }

/* Focus (keyboard nav) */
a:focus { outline: 2px solid #7c3aed; }

/* Visited */
a:visited { color: #a78bfa; }

/* Button-style link */
.btn-link {
  display: inline-block;
  padding: 10px 20px;
  background: #7c3aed;
  color: white;
  border-radius: 8px;
  text-decoration: none;
}

Common Mistakes

Using "click here" as link text
Screen readers announce links out of context. "Click here" tells nobody where the link goes. Write "Download the HTML cheat sheet" — that's descriptive and useful to everyone.
Missing rel="noopener noreferrer" on _blank links
External links opened in a new tab without this attribute allow the destination site to access your page via window.opener. Always add it — it's one attribute and costs nothing.
Using javascript:void(0) in href
If you need a clickable element that doesn't navigate anywhere, use a <button> tag — not <a href="javascript:void(0)">. The javascript: protocol breaks keyboard navigation and screen readers.
Try It — 5 Link Challenges
1Create a link to https://tipsinlearning.blogspot.com with the text "Learn Web Development Free"
2Add target="_blank" rel="noopener noreferrer" and confirm it opens in a new tab
3Create an email link with mailto: and a phone link with tel:
4Wrap an <img> tag inside an <a> tag to make a clickable image
5Style your link to look like a purple button using CSS padding, background-color, and border-radius
Lesson Summary
1The <a href=""> tag creates links — href holds the URL, the content between tags is what users see
2Use target="_blank" to open in a new tab — always pair it with rel="noopener noreferrer"
3href supports full URLs, relative paths, #anchors, mailto:, and tel:
4Write descriptive link text — not "click here". Screen readers and Google both depend on it
5The download attribute makes a link trigger a file download instead of navigation
6Use rel="nofollow" for untrusted links and rel="sponsored" for paid/affiliate links

Questions & Answers

Common questions beginners ask about this topic:

What's the difference between absolute and relative URLs?

An absolute URL is a complete web address — it includes the protocol (https://), the domain, and the path. It works from anywhere on any site. A relative URL is a partial path relative to the current page's location. If your page is at /lessons/html.html and you link to css.html, the browser assumes /lessons/css.html. Use absolute URLs for external sites. Use relative URLs for links within your own site — they're shorter and won't break if you change domains.

Should I always open external links in a new tab?

It's a common convention but not a rule. Opening external links in a new tab keeps users on your page while they visit the external resource. When you do use target="_blank", always add rel="noopener noreferrer". Without it, the new tab can access your page via JavaScript's window.opener — a real security vulnerability. On mobile, new-tab behavior is less intuitive, so some designers avoid it entirely.

Why does 'Click here' make a bad link?

Screen readers let users jump between links to navigate a page quickly. When every link says 'Click here', there's no way to know where any of them go without reading surrounding text. Search engines also use link text as a ranking signal for the linked page — 'Learn HTML basics' tells Google what the destination covers; 'click here' tells Google nothing. Descriptive link text costs nothing extra and improves both accessibility and SEO.

What does rel='noopener noreferrer' do?

noopener prevents the new tab from accessing your page's window object via JavaScript — closing a security hole. noreferrer stops the browser from sending a Referer header to the destination site, so they don't know your page linked to them. Use both together whenever you use target="_blank" on external links. Modern browsers apply noopener automatically for _blank links, but it's still good practice to write it explicitly.

Can I make an image into a clickable link?

Yes — just wrap the <img> tag inside an <a> tag. The entire image becomes clickable: <a href="url"><img src="logo.png" alt="Logo"></a>. Make sure the alt attribute on the image describes where the link goes, since that's what screen readers will announce as the link text.

Post a Comment

Previous Post Next Post