link
In this module we will do the following:
Describe
href
and using links. Discuss the<a></a>
tag.Study different ways to hyperlink. (internal and external)
File Location
For this module, you should be working in the following location:
Anchor Tags
An anchor is a piece of text that marks the beginning and end of a hypertext link. It is indicated in HTML using the <a></a>
tag and will display text between the opening and closing tags as the standard, blue, underlined link that you have probably become accustomed to seeing.
Hrefs
Within an <a>
tag, you commonly add a href
which allows you to direct the link to the url or local path you want to go. Common syntax for this is <a href="www.google.com">Google</a>
.
Sample Code
Add the following sample code to your file:
Targets
When you run your code using alt + b
, all of the links that appear on your browser page should be functional. Clicking on them will navigate you to other places. Notice though, there is a slight difference between the first and third example: target="blank" is what causes the link to be opened in a new tab when you click on it.
Relative paths
In the second example above, you wrote an <a></a>
tag that linked to a local file. To do this, we used "relative pathing". This is an important concept that is used very frequently during development. For now, just recognize that you are connecting this .html file with another .html file.
Challenge
Now that you've got examples of different ways to write anchor tags, see if you can write a few that link to some of your favorite web pages!
Last updated