2. Anchor tag #
Created Wednesday 17 June 2020
Why #
Used for linking to other pages.
Syntax: <a href=""> </a>
is used for making links.
What can it link to: #
- Other URLs/html pages
- Files
- Link element on the same page, using id attribute of destination. Syntax:
<a href="#idname"></a>
. Jump, no reloads 😃️! - Email address, phone number, SMS.
- Email -
mailto:example@gmail.com
?subject=Subject&body=Content
- SMS -
sms:1234567890?body=Content
- Phone call -
tel:1234567890
- Email -
This opens the relevant app. subject and body may be skipped.
- Huge Plus: As anchor is an open tag, We can set images to act as links, and technically anything.
Other attributes #
<a target="_blank"></a>
opens the link in new tab. It has 3 more values, see MDN.<a download></a>
boolean attribute will download the file. Of course thehref
needs to be a valid file.
Relative vs absolute address/paths #
- Relative is based current folder address.
- Absolute is based on the root (/home or analogue) folder.