CS45
The <a> tag[edit]
In HTML, the <a> tag
, or anchor element, allows users to create hyperlinks. Hyperlinks are able to link one webpage to another using the href
attribute. This feature can be used to link pictures, websites, emails, phone numbers, and other information on a website.
Let's look at an example of this:
Linking to another website[edit]
<a href="https://www.examplewebsite.com">Website!</a>
To understand how this line of code works, let's break it down into smaller components. The line begins with <a>
and ends with </a>
. The information for the hyperlink must be included within these two tags, and it is important to have both, otherwise the code will not function as intended. Next, we include the href
attribute followed by an "=" sign and quotation marks on both sides of the page we want to link to. To link the webpage to text, follow the closing quotation with a ">" symbol and write the text you would like to link to the other webpage.
Linking an image[edit]
<a href="https://www.examplewebsite.com"> <img src="exampleimage.png"> </a>
Linking an image is similar to what we did before, but instead of hyperlinking text, we exchange it for an image. Include a new line of text with the <img>
tag along with "src=", to indicate the source of the image. Insert the image source inside quotation marks, then close the line with a ">" symbol.
Congratulations, you've learned about the <a> tag
! Try using this tag in your website to reference other pages in your own.