HTML links are known as hyperlinks
You can click on a link to navigate to another webpage
A link does not have to be text, it can be any HTML element.
The HTML <a>
tag defines a hyperlink. It has the following syntax:
The most important attribute of the <a>
element is the href
attribute, which indicates the link's destination.
The link text is the part that will be visible to the reader.
Clicking on the link text, will send the reader to the specified URL address.
Below you can see an example of creating a link to Amazon
By default, links will appear as follows in all browsers:
By default, the linked page will be displayed in the current browser tab. To change this, you must specify the links target.
The target
attribute specifies where to open a linked page.
The target
attribute can have one of the following values:
_self
- Default. Opens the document in the same window/tab as it was clicked_blank
- Opens the document in a new window or tab._parent
- Opens the document in the parent frame_top
- Opens the document in the full body of the windowThe following example opens Google in a new tab:
Both wxamples above use an absolute URL (a full web address) in the href
attribute.
A local link (a link to a page within the same website) is specified with a relative URL (without the "https://www" part):
Use mailto:
inside the href
attribute to create a link that opens the user's email program (to let them send a new email):