Relative URLs contain no protocols or domain information. This is convenient because they are shorter, but can only reference files in the same path.
It also should be noted that in the language of web design, the index.html
file is referred to as the home page once hosted, as it becomes the “entry” to your site. It is also the page most users will return to again and again as your “base of opperations,” as it were.
Relative URL’s help with building a site locally before pushing it to the web. This way you can develop on your local machine, and still have links to pages be valid.
But how do we navigate to a different directory using a relative URL?
Well, if a single ".
" states that we need to remain in the current level of our directory heirarchy, two "..
" is effectively saying "to find this file, begin here and then step back a directory."
Here are some ways you would link these files:
<a href="./pages/about.html">To About</a>
<a href="./contact.html">Contact Me</a>
<a href="../">Back to Home</a>
We can use the “id” attribute in HTML to create links to specific portions of a page.
One attribute that can be assigned to almost any HTML element is id
. This attribute is used to assign unique identifiers to each element, so that those specific elements can be referenced through HTML, CSS, or JavaScript. When assigning an element an id, you should ensure that no other element is given the same.
To assign an element an unique identifier, you should include the following code in the opening tag.
<h3 id="first-heading">"Page to Page" Section</h3>
<h3 id="second-heading">"Specific Part of the Same Page" Section</h3>
NOTE: IDs should be treated like variables in other languages, with regards to the naming conventions. If you would like a refresher on HTML Attributes, please read W3School’s page about the subject.
With regard to naming conventions, please consider the following:
name=“value”
).name="exampleValueHere"
)-
) character._
) character.To link to an HTML element with an assigned id, simply use the id in the hyper-reference (href
), prepended with a hashtag character (#
).
In the following code, the link in line 1, would connect to the h2
element in line 3.
<a href="#first-heading">"Page to Page" Section</a>
<br />
<a href="#second-heading">"Specific Part of the Same Page" Section</a>
See it in action!
Notice how the URL changed in your address bar when you clicked one of those links?
Read pages 80-93 of Chapter 04 in Duckett.