Lesson 7: Building Hyperlinks in HTML

Master the art of creating links to navigate between web pages, sections, and external resources

Start Learning

Basic Text Links

Text links are the most common type of hyperlink, created using the <a> tag with text content.

Simple Text Link

The most basic way to create a hyperlink:

<!DOCTYPE html>
<html>
<head>
    <title>Text Link Example</title>
</head>
<body>
    <h1>Welcome to My Website</h1>
    <p>Visit our <a href="about.html">About Page</a> to learn more.</p>
    <p>Check out <a href="https://google.com" target="_blank">Google</a>.</p>
</body>
</html>

Result:

Welcome to My Website

Visit our About Page to learn more.

Check out Google (opens in new tab).

Styling Links with CSS

Customize link appearance with CSS:

<style>
    a {
        color: #e74c3c;
        text-decoration: none;
        transition: color 0.3s;
    }
    
    a:hover {
        color: #c0392b;
        text-decoration: underline;
    }
    
    a:active {
        color: #8e44ad;
    }
    
    a:visited {
        color: #16a085;
    }
    
    .special-link {
        background: #3498db;
        color: white;
        padding: 5px 10px;
        border-radius: 4px;
    }
    
    .special-link:hover {
        background: #2980b9;
    }
</style>

<a href="products.html" class="special-link">View Products</a>

Graphical Links

Images can also function as hyperlinks by wrapping them with the <a> tag.

Image as a Link

Create clickable images:

<!DOCTYPE html>
<html>
<head>
    <title>Graphical Link Example</title>
</head>
<body>
    <h2>Click the logo to visit our homepage</h2>
    <a href="index.html">
        <img src="logo.png" alt="Company Logo" width="200">
    </a>
    
    <h2>Social Media Links</h2>
    <a href="https://facebook.com" target="_blank">
        <img src="facebook.png" alt="Facebook" width="50">
    </a>
    <a href="https://twitter.com" target="_blank">
        <img src="twitter.png" alt="Twitter" width="50">
    </a>
</body>
</html>

Result:

Click the logo to visit our homepage

Company Logo

Social Media Links

Facebook Twitter

Email Links

Email links automatically open the user's default email client with a pre-filled message.

Basic Email Link

Create a link that opens the user's email client:

<!DOCTYPE html>
<html>
<head>
    <title>Email Link Example</title>
</head>
<body>
    <h2>Contact Us</h2>
    <p>Send us an email: <a href="mailto:[email protected]">[email protected]</a></p>
    
    <h3>Email with Subject and Body</h3>
    <a href="mailto:[email protected]?subject=Website%20Inquiry&body=Hello%20team,">
        Email with pre-filled content
    </a>
</body>
</html>

Result:

Contact Us

Send us an email: [email protected]

Email with Subject and Body

Email with pre-filled content

Anchor Links

Anchor links allow navigation to specific sections within the same page.

Creating Anchor Points

Use the id attribute to create anchor points:

<!DOCTYPE html>
<html>
<head>
    <title>Anchor Links</title>
</head>
<body>
    <h1>Table of Contents</h1>
    <ul>
        <li><a href="#section1">Section 1</a></li>
        <li><a href="#section2">Section 2</a></li>
        <li><a href="#section3">Section 3</a></li>
    </ul>
    
    <h2 id="section1">Section 1</h2>
    <p>Content for section 1...</p>
    
    <h2 id="section2">Section 2</h2>
    <p>Content for section 2...</p>
    
    <h2 id="section3">Section 3</h2>
    <p>Content for section 3...</p>
    
    <p><a href="#">Back to Top</a></p>
</body>
</html>

Result:

Table of Contents

Section 1

This is the content for section 1. Anchor links allow users to jump directly to specific sections of a page without scrolling.

Section 2

This is the content for section 2. These are especially useful for long pages with multiple sections like documentation, FAQs, or blog posts.

Section 3

This is the content for section 3. Notice how clicking the links in the table of contents smoothly scrolls to the relevant section.

Back to Top

Interactive Link Playground

Experiment with different link properties in real-time:

Link Configuration

Result Preview

This is a paragraph with an interactive link that you can customize using the controls on the left.

Hover over the link to see the hover effect, and click to see the active state.

HTML Code

<a href="https://example.com" target="_self">Click Me</a>

CSS Code

a {
    color: #2196f3;
    text-decoration: none;
}

a:hover {
    color: #0d47a1;
}

Complete Example: Navigation Menu

<!DOCTYPE html>
<html>
<head>
    <title>Navigation Menu</title>
    <style>
        nav {
            background: #2c3e50;
            padding: 1rem;
        }
        
        .nav-menu {
            display: flex;
            list-style: none;
            margin: 0;
            padding: 0;
        }
        
        .nav-menu li {
            margin: 0 10px;
        }
        
        .nav-menu a {
            color: white;
            text-decoration: none;
            padding: 10px 15px;
            border-radius: 4px;
            transition: background 0.3s;
        }
        
        .nav-menu a:hover {
            background: #3498db;
        }
        
        .nav-menu a.active {
            background: #e74c3c;
        }
        
        .dropdown {
            position: relative;
        }
        
        .dropdown-content {
            display: none;
            position: absolute;
            background: white;
            min-width: 160px;
            box-shadow: 0 8px 16px rgba(0,0,0,0.2);
            z-index: 1;
        }
        
        .dropdown:hover .dropdown-content {
            display: block;
        }
        
        .dropdown-content a {
            color: #333;
            padding: 12px 16px;
            display: block;
        }
        
        .dropdown-content a:hover {
            background: #f1f1f1;
        }
    </style>
</head>
<body>
    <nav>
        <ul class="nav-menu">
            <li><a href="index.html" class="active">Home</a></li>
            <li><a href="about.html">About</a></li>
            <li class="dropdown">
                <a href="services.html">Services</a>
                <div class="dropdown-content">
                    <a href="web.html">Web Design</a>
                    <a href="graphic.html">Graphic Design</a>
                    <a href="seo.html">SEO</a>
                </div>
            </li>
            <li><a href="portfolio.html">Portfolio</a></li>
            <li><a href="contact.html">Contact</a></li>
        </ul>
    </nav>
    
    <div style="padding: 20px;">
        <h1>Welcome to Our Website</h1>
        <p>This is a complete navigation menu example using hyperlinks.</p>
    </div>
</body>
</html>

Result:

Welcome to Our Website

This is a complete navigation menu example using hyperlinks. Hover over "Services" to see the dropdown menu.