CS 100 (Learn)CS 100 (Web)Module 07


HTML :: Links

HTML was created to add hyperlinks to web pages.

To insert a hyperlink, you use the anchor <a> paired tag. Everything between the opening <a> and the closing </a> tags becomes a hyperlink (for example, clickable).

HTML

This is my <a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ">favourite video</a>.

web browser

This is my favourite video.

 

The most important attribute of the <a> tag is the href (hypertext reference) attribute, which specifies the destination address of the link (what to display if the link is selected or clicked).

Internal Links

If the destination address is another page in the same folder, you can omit the protocol and destination computer and simply specify the file directly.

HTML

See my <a href="goodbye.html">goodbye</a> page.

 

For example, if you create a goodbye.html file in the same folder as your hello.html file, you can link to it from hello.html using the above example.

Links within Documents

It is even possible to link to an element within the same web page.

This usually only makes sense for long web pages.

To link to an element in the current page, the element must have an additional id attribute. You can add a unique id attribute to any element (<tagname id="idname">).

To link to the element, the destination (href) is the id preceded by a number sign (or hashtag #). For example, <a href="#idname">.

HTML
<body>
  ...

  <h2 id="intro">Introduction</h2>`

  ...

  <a href="#intro">return to the introduction</a>
 

You can even link to a specific element that appears on another page.

HTML

Go to the <a href="https://en.wikipedia.org/wiki/HTML#History">history section</a> of the Wikipedia HTML page.

web browser

Go to the history section of the Wikipedia HTML page.

 

This example will take you directly to the history (#History) section of the Wikipedia page.

Email Links

If you wish to provide a link to an email address, the destination (href) is simply "mailto:address". For example:

HTML

Contact your <a href="mailto:cs100@uwaterloo.ca">ISAs</a> with any questions.

web browser

Contact your ISAs with any questions.

 

If your web browser is configured correctly, clicking on the above link should launch your email app.