Learning Resources
 

Using href Attribute


The HREF Attribute
To create a link, you have to know the web address of the file you want to link to, whether it's another web page of your own site, another website, or a link to file such as a PDF document, sound file, or another type of file.

Suppose you wanted to link to the front page of my site. The web address is: https://www.Vskills.com. You'd code the link like this:

Vskills

The href part, shown in dark blue text, is short for hypertext reference. This is the attribute that defines the address of the file you want to link to.

The equal sign always connects an attribute to the attribute's value. So in this case, href is the attribute, and https://www.Vskills.com is the value. The value is always enclosed in quotation marks.

The Vskills part, shown in green text, is the anchor text, or sometimes called the link text. This is the part of a link that is clickable.

If you link to a page on another site you need to use the full web address as shown in the example above. If you're linking to a different page on your own site you only need to use the page name and extension if the page is keep in the same directory.

For example, suppose you want to link to a page you've saved with the name of MyPage.html. You'd code it like this:

My Page

By linking to your own internal pages without using the full web address your pages will load faster. If you use the full web address the browser goes back out to the Internet to find your site all over again, which takes longer. If you don't use the full path the browser only checks on your site for the file.

File names, which includes the name of the web page and the extension, are case sensitive. That means you must use the same capitalization in the web address of the file that was used when the file was saved.