0% completed
The <a>
tag, also known as the anchor tag, is used to create hyperlinks in HTML. A hyperlink allows users to click and navigate to another location, whether it's another web page, a specific section within the same page, or an external website. The <a>
tag is versatile and fundamental for building interconnected web content.
The basic syntax for creating a hyperlink using the <a>
tag is as follows:
<a href="URL">Link Text</a>
<a>
: The opening anchor tag that starts the hyperlink.href="URL"
: The href
attribute specifies the destination URL where the link points to.Link Text
: The clickable text that users will see and interact with. It is also called Anchor text.</a>
: The closing anchor tag that ends the hyperlink.<a>
TagLet's explore some practical examples of using the <a>
tag to create hyperlinks.
In this example, we'll create a hyperlink that directs users to an external website, designgurus.io
.
Explanation:
<a>
tag creates a clickable link with the text "Visit DesignGurus.io".href="https://designgurus.io"
attribute specifies that clicking the link will navigate the user to https://designgurus.io
.You can create links that navigate to specific sections within the same web page using the id
attribute.
Explanation:
<a href="#contact">Go to Contact Us Section</a>
creates a link that, when clicked, scrolls the page to the element with the id="contact"
.<h2 id="contact">Contact Us</h2>
defines the target section. The id
attribute uniquely identifies this heading so that the link knows where to navigate.By default, hyperlinks open in the same tab. However, you can modify this behavior to open links in a new browser tab using the target
attribute.
Explanation:
<a>
tag creates a clickable link with the text "Visit DesignGurus.io".href="https://designgurus.io"
attribute specifies the destination URL.target="_blank"
attribute tells the browser to open the link in a new tab, keeping the current page open for the user.Understanding how to create and manage hyperlinks is crucial for building navigable and user-friendly websites. In the next lesson, we'll explore how to turn an image into a clickable link, enhancing the interactivity and visual appeal of your web pages.
.....
.....
.....