To make a link in HTML, use the anchor tag (<a>) with the href attribute to specify the destination URL. The basic syntax is <a href="URL">Link Text</a>, where "URL" is the address you want to link to and "Link Text" is the clickable text displayed.
Links are created using the HTML anchor element, which serves as a reference point within a document. When a user clicks on the link text, their browser navigates to the specified URL. This can be a webpage, file, email address, or phone number.
The anchor tag has several key parts:
HTML links can connect to various resources:
| Link Type | Example | Description |
|---|---|---|
| Web page | <a href="https://www.example.com">Example Website</a> | Links to another website |
| Email address | <a href="mailto:[email protected]">Email Us</a> | Opens the user's default email client |
| File download | <a href="documents/report.pdf">Download Report</a> | Downloads a file from your server |
| Phone number | <a href="tel:+1234567890">Call Us</a> | Initiates a phone call on mobile devices |
Many beginners make these errors:
A common correction needed is properly escaping ampersands in URLs: use & instead of & in your href values.
Here's how to build a simple navigation menu with multiple links:
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About Us</a></li>
<li><a href="services.html">Services</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</nav>
This creates a bulleted list of navigation links that take users to different pages on your website.
For more complex interactive elements like dropdown menus, you'll need to combine HTML with CSS and JavaScript. See how to create a dropdown menu in HTML for detailed instructions.
Remember that links are fundamental building blocks of web development. Mastering them is essential before moving on to more advanced topics like forms or APIs. If you're new to coding, start with the basics of how to make HTML code before diving deeper into link creation techniques.