What is <a> element in HTML?

The <a> element in HTML is the anchor element. We use this to integrate URLs (hyperlinks, email addresses, files, etc.) into the webpage via the href attribute, which is enclosed within the opening <a> and closing </a> tags.

Conventions

There are some conventions as to how these links appear. All links are underlined by default (this can be modified by using the CSS property text-decoration). Conventions for colors include:

  • unvisited links are blue
  • visited links are purple
  • active links are red

If the tag has no href attribute specified, it can be kept as a placeholder to add a link later on.

Attributes supported

The <a> tag has many attributes in addition to global attributes, including:

href


download


rel


target

Sets the URL to which the link will take the user

Clicking on the href link will download the target file specified by download tag

Sets the relationship between the current page and the page to which href links

Specifies where the page or document should be opened (e.g., in a new tab or on the same one)

Code

The following tag shows how we use the <a> tag for hyperlinks:

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved