Adding Links
Hyperlinks are added to your site using the anchor <a>
element.
Making Links
- Make a new anchor
<a>
element - Place the text the user will see for the link inside the open and close tags.
- In the open tag, add a
href
attribute with the URL the user will be redirected to
href
attribute
The href
attribute is used to set the URL the user will be sent to when you click the link!
Absolute URL
When linking to external sites, the entire URL needs to be used.
Relative URLs
When linking to pages on your own site, you can use relative URLs!
These can be a little confusing, so first let's imagine how your site is structured as a file system.
Let's imagine your current page is at the URL https://yoursite.com/characters/princes/red.html
Your origin is https://yoursite.com/
Your directory is /characters/princes/
Your current file is /characters/princes/red.html
type | href | result |
---|---|---|
origin-relative url | /stories |
https://yoursite.com/stories |
same directory url | ./blue.html |
https://yoursite.com/characters/blue.html |
parent directory url | ../ |
https://yoursite.com/characters/ |