HTML HTML Tutorial HTML Forms HTML Graphics HTML Media HTML APIs HTML Tags



HTML Tag: a

The HTML tag <a> is used to create hyperlinks in web pages. It stands for "anchor" and is one of the most commonly used tags in HTML. Hyperlinks are used to connect one web page to another or to a specific section within the same page.

The <a> tag requires two attributes: href and text. The href attribute specifies the URL of the page or section that the link should point to. The text attribute specifies the text that should be displayed as the link.

Here are some examples of how the <a> tag can be used:

Example 1: Basic Link

The following code creates a basic hyperlink:

<a href="https://www.example.com">Click here to visit Example.com</a>

This will create a link that says "Click here to visit Example.com" and will take the user to the Example.com website when clicked.

Example 2: Link to a Specific Section

The <a> tag can also be used to link to a specific section within the same page. To do this, the href attribute should be set to the ID of the section that the link should point to. For example:

<a href="#section2">Click here to jump to Section 2</a>

Assuming that there is a section on the page with the ID "section2", this link will take the user directly to that section when clicked.

Example 3: Link to an Email Address

The <a> tag can also be used to create links to email addresses. To do this, the href attribute should be set to "mailto:" followed by the email address. For example:

<a href="mailto:example@example.com">Click here to send an email to Example</a>

This will create a link that, when clicked, will open the user's default email client and create a new email addressed to "example@example.com".

Example 4: Link to a File

The <a> tag can also be used to create links to files, such as PDFs or images. To do this, the href attribute should be set to the URL of the file. For example:

<a href="https://www.example.com/files/example.pdf">Click here to download Example.pdf</a>

This will create a link that, when clicked, will download the file located at "https://www.example.com/files/example.pdf".

These are just a few examples of how the <a> tag can be used. It is a versatile and essential tag for creating links in HTML.

References

Activity