codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🎨

HTML & CSS

6 / 59 topics
1Introduction to HTML2HTML Elements3HTML Attributes4HTML Document Structure5HTML Text Formatting6HTML Links7HTML Images8HTML Lists9HTML Tables10HTML Forms
Tutorials/HTML & CSS/HTML Links
🎨HTML & CSS

HTML Links

Updated 2026-04-20
3 min read

HTML Links

HTML links are a fundamental part of web development, allowing users to navigate between different pages or sections within a website. In this section, we will explore how to create and customize links using HTML and CSS.

Introduction to HTML Links

A link in HTML is created using the <a> (anchor) tag. The most basic usage involves specifying the href attribute, which contains the URL of the page the link should point to.

<a href="https://www.example.com">Visit Example</a>

In this example, clicking on "Visit Example" will take the user to "https://www.example.com".

Types of Links

Absolute Links

Absolute links use a full URL. They are useful when linking to external websites.

<a href="https://www.example.com">External Website</a>

Relative Links

Relative links specify the path to the destination file relative to the current page. This is commonly used for internal navigation within a website.

<a href="/about.html">About Us</a>

In this example, /about.html is assumed to be in the root directory of the website.

Anchor Links

Anchor links allow you to jump to specific sections within the same page. This is done by using an id attribute on the target element and referencing it with a hash (#) in the link.

<a href="#section1">Go to Section 1</a>

<div id="section1">
    <h2>Section 1</h2>
    <p>This is section one content.</p>
</div>

Link Attributes

href Attribute

The href attribute specifies the destination URL. It can be an absolute or relative path.

<a href="https://www.example.com">External Website</a>
<a href="/about.html">About Us</a>
<a href="#section1">Go to Section 1</a>

target Attribute

The target attribute specifies where to open the linked document. Common values include:

  • _self: Opens in the same frame (default).
  • _blank: Opens in a new tab or window.
  • _parent: Opens in the parent frame.
  • _top: Opens in the full body of the window.
<a href="https://www.example.com" target="_blank">Visit Example</a>

rel Attribute

The rel attribute specifies the relationship between the current document and the linked document. Common values include:

  • noopener: Prevents the new page from having access to the original page's window.opener property.
  • noreferrer: Prevents the Referer header from being sent when navigating away from the link.
<a href="https://www.example.com" target="_blank" rel="noopener noreferrer">Visit Example</a>

Styling Links with CSS

Links can be styled using CSS to improve their appearance and usability. Common properties include:

  • color: Sets the color of the link text.
  • text-decoration: Controls the underline style.
  • cursor: Changes the cursor icon when hovering over the link.
a {
    color: blue;
    text-decoration: none;
}

a:hover {
    color: darkblue;
    text-decoration: underline;
}

Pseudo-Classes

CSS pseudo-classes can be used to style links based on their state:

  • :link: Styles unvisited links.
  • :visited: Styles visited links.
  • :hover: Styles links when hovered over.
  • :active: Styles links during the click event.
a:link {
    color: blue;
}

a:visited {
    color: purple;
}

a:hover {
    color: darkblue;
}

a:active {
    color: red;
}

Best Practices

Accessibility

  • Use Descriptive Text: Ensure link text is descriptive and meaningful. Avoid using generic phrases like "click here".

    <a href="https://www.example.com">Learn more about Example</a>
    
  • Keyboard Navigation: Links should be navigable via keyboard, especially for users with disabilities.

SEO

  • Use Relevant Keywords: Include relevant keywords in link text to improve search engine rankings.

    <a href="/services.html">Our Services</a>
    
  • Avoid Excessive Linking: Overusing links can dilute their effectiveness and negatively impact SEO.

Performance

  • Minimize External Links: Reduce the number of external links to minimize page load times and improve user experience.

  • Use rel="noopener noreferrer": When opening links in a new tab, use rel="noopener noreferrer" for security reasons.

Conclusion

HTML links are essential for creating interactive and navigable websites. By understanding how to create different types of links, customize their appearance with CSS, and follow best practices for accessibility and SEO, you can enhance the user experience on your website.


PreviousHTML Text FormattingNext HTML Images

Recommended Gear

HTML Text FormattingHTML Images