Web / HTML

Learning HTML Lesson 02 - Anchor Element

by Libz Mbanje
24 Nov 2015 at 23:47hrs | 2484 Views
This is a continuation from 'Learning HTML Lesson 01'. In this lesson we will focus on creating a hyperlink. Hyperlinks can be used to locate a spot on the same page or any an external file.
To create a hyperlink in HTML an Anchor Element '<a>' has to be used. The Anchor Element '<a>' requires attribute href attribute which indicates the link target '<a href="link target">'.

Using the code from lesson 1 create a file 'lesson_02.html' and add a hyperlink to 'lesson_01.html'

<html>
<head></head>
<body>
<h1>My First HTML Header</h1>
<p>My First HTML Paragraph</p>
<a href="lesson_01.html">Lesson 1</a>
</body>
</html>

Save and open the file (lesson_02.html) with a web browser of your choice,  below is a screen-shot taken from Firefox web browser.

Screen-Shot Results

Now that we have created a hyperlink lets add another attribute ('target') to the element '<a href="lesson_01.html">'
The attribute 'target' specifies where to display the linked resource.

_self: This value is the default if the attribute is not specified. It loads the response into the same as the current one

_blank: Load the response into a new window.

_parent: Behaves as _self

_top: Load the response into the full, original window, cancelling all other frames

In this case we will set attribute 'target="_self"'

<html>
<head></head>
<body>
<h1>My First HTML Header</h1>
<p>My First HTML Paragraph</p>
<a href="lesson_01.html" target="_self">Lesson 1</a>
</body>
</html>

Save and test.

Source - a{C}
More on: HTML



Chat Login

Register | Forgot password