For so many reasons when we are creating websites we would want to link to other resources on other people's website or on our page.
Linking is made possible by using the anchor element (<a>...</a>). To make a text a link, we simply put it between the opening (<a>) elemennt and closing (</a>) element and use the href attribute to specify the URL of the target page,
we can also make an image a link by putting the img element in the anchor element.
Most browsers displays a linked text in blue and underlined while visited links in purple by default
STRUTURE FOR AN ANCHOR ELEMENT
<a href="URL"> Linked Content </a>
HREF Attributes
We tell the browsers the document or website we want to link to by using the href attribute to provide the URL of document or website, we mostly point to other HTML document, however we could also point to other web resources such as images, video, audio files.
We could possibly run into errors when we are specifying our URLs and that's why we must understand the type of URL and the way they function in their use-cases
Absolute URLs:
Absolute URLs provide the full URL for the document including the protocol (http:// or https://), the domain name and the pathname as necessary. Absolute URLs are used to pointing to resources out on the web or internet.
EXAMPLE OF AN ABSOLUTE LINK TO GOOGLE.COM:
<a href="https://www.google.com"> Go to GOOGLE</a>
Relative URLs:
Relative URLs provides the pathname to a file relative to the current document. They are used when linking to documents or resources on your website (on the same server) and requires no protocol or domain name.
Since Relative URLs have to be relative the current document, we have to understand the structure of our files and relation of our files to each other to ensure proper functioning of relative URLs.
Linking within a Directory
When linking to a file in the same directory, you need to provide only the name of the file.
when the URL is just a file name, the server looks in the current directory that contains the document that contains the link
A link to a filename indicates the linked file is in the same directory as the current document
Linking to a Lower Directory
When linking to a lower directory, you are require to include the directory of the file
FOR EXAMPLE:
<a href="Cars/Toyota.html">Toyota</a>
The directory named Cars must be in a lower directory to the current working document, if the directory are two steps away from the working document, you have to tells to go down
two directory to the actual file by listing the URL of the directory out by seperating with a forward slash(/)
When you link to a file in a lower directory ,the pathname contains the names of each sub directory you go through to get the file
Linking to a Higher directory
To link from a current document to a higher directory, we make use of a unix convention (../), when the browser sees your URL with (../) convention,
it tells the browser to go up one directory and then follow the path to the specified file.
if you are required to move up the directory more than once,you would specify the ../ convention the number of times it has to move up a directory
Each ../ at the begining of the pathname tells the browser to go up one directory level to look for the file
Target Attribute
We use an absolute links to other webpage, you probably won't want your users to totally forget about your page or find it stressful to find their ways back to your page, so you might want to
determine where your clicked link opens up to your users, you can determine that by using the Target attribute
Values of Target attribute:
_blank - used to open a page in a new browser window
_self - used to open a page in the same browser windows as the previous