Resources | Subject Notes | Information Communication Technology ICT
Understand the function of an anchor in HTML.
An anchor is an HTML element that creates a hyperlink to another piece of content within the same page. It allows users to quickly navigate to a specific section of a webpage.
Anchors provide several benefits:
An anchor is created using the (anchor) tag. The
href
attribute of the tag specifies the destination of the link. When the
href
attribute points to an ID of another element on the same page, it creates an internal link (an anchor).
Consider the following HTML structure:
This is the introduction to the topic.
This section provides more details about the topic.
This is the conclusion of the topic.
To create an anchor to the Section 2: Details element, we would use the following HTML:
Go to Section 2
And the Section 2: Details element would have an id
attribute:
Section 2: DetailsThis section provides more details about the topic.
Go to Section 2
: This creates a hyperlink that points to the element with the id="section2"
. The #
symbol in the href
attribute indicates an internal link.
: This defines the section that the anchor links to. The id="section2"
attribute provides a unique identifier for this element.
Anchor Element | Destination Element |
---|---|
Go to Introduction | Section 1: Introduction |
Go to Details | Section 2: Details |
Go to Conclusion | Section 3: Conclusion |
Anchors are a fundamental part of website authoring, enabling better navigation and accessibility. They work by linking to elements with specific id
attributes on the same page.