<a> (Anchor) ElementKnow and understand the function of an anchor (<a>) in HTML web pages, how it fits into the three‑layer web‑development model, and how it meets the requirements of the Cambridge IGCSE ICT (0417) syllabus (Sections 21.1‑21.3).
target, rel, download). No scripting language is required for the IGCSE exam.The anchor lives in the content layer but its appearance is set in the presentation layer and its behaviour is controlled by its attributes (behaviour layer).
An HTML document is divided into two main sections:
<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Demo page showing anchor usage">
<meta name="keywords" content="HTML, anchor, link">
<meta name="author" content="Your Name">
<title>Anchor Demo</title>
<link rel="stylesheet" href="styles.css">
<div> containers, and the <a> element.All anchors are placed inside the <body>, but their visual style may be defined in the head‑linked CSS file.
An anchor creates a hyperlink that lets a user jump from one location to another. It can link to:
<a href="URL" target="_blank" rel="noopener" title="Link description">Link text</a>
href – destination address (required).target – where the linked document opens (blank, self, parent, top).rel – relationship; for new‑tab external links use noopener (or noopener noreferrer) for security.title – optional tooltip; improves accessibility and SEO.<a href="https://www.bbc.com" target="_blank" rel="noopener" title="BBC News – world news">BBC News</a>
<a href="#section2">Go to Section 2</a>...
<h3 id="section2">Section 2</h3>
<a href="chapter2.html#summary">Read the summary</a><h2 id="summary">Summary</h2>
<a href="mailto:info@example.com?subject=Enquiry">Email us</a>
<a href="files/report.pdf" download="AnnualReport.pdf">Download Report</a>
<a href="gallery.html#photo5"><img src="thumb5.jpg" alt="View photo 5">
</a>
<a href="video.mp4"><img src="video-thumb.jpg" alt="Play video">
</a>
| Attribute | Purpose | Typical Values / Example |
|---|---|---|
| href | Destination URL or fragment identifier. | https://www.example.com, #section3, chapter2.html#summary |
| target | Where the linked document opens. | blank, self, parent, top |
| rel | Relationship between current page and linked resource. | noopener, noreferrer, stylesheet, prefetch |
| title | Tooltip / advisory information for accessibility and SEO. | "Visit the official site" |
| download | Indicates the link is for downloading a file. | (empty) or "myfile.zip" |
| id | Creates a named anchor for internal or cross‑page linking. | section5 |
| class | Assigns the element to a CSS class (re‑usable styling). | class="navLink" |
https://www.example.com/images/photo.jpg
images/photo.jpg../assets/style.css
/images/photo.jpg
Links are styled in the presentation layer. Remember the CSS hierarchy used in the exam:
blockstyle="…" attribute (least powerful)Classes (.className) can be reused on many elements; IDs (#idName) must be unique.
| Selector | Property | Example |
|---|---|---|
| a | color, text‑decoration | color:#0066cc; text-decoration:none; |
| a:visited | color | color:#660099; |
| a:hover | color, text‑decoration | color:#ff6600; text-decoration:underline; |
| a:active | color | color:#ff0000; |
Example – external stylesheet (styles.css)
/* external stylesheet */a {
color: #0066cc;
text-decoration: none;
}
a:visited {
color: #660099;
}
a:hover {
text-decoration: underline;
color: #ff6600;
}
a:active {
color: #ff0000;
}
/* a reusable class for navigation links */
.navLink {
font-weight: bold;
margin-right: 15px;
}
href. An empty or # value without JavaScript makes the link useless.target="_blank" and rel="noopener" (or rel="noopener noreferrer") for security.id on the target element.title attribute to provide extra information for screen‑readers and SEO.href empty or using href="#" without JavaScript.<a> tag – can break the page layout.id and the deprecated name attribute – id is the modern standard.id to more than one element – IDs must be unique.In an exam you may be asked to analyse or evaluate a given set of links. Use the prompts below to structure your answer:
Prompt: “Explain why you would use
target="_blank"withrel="noopener"for external links, but not for internal navigation.”Suggested answer structure:
- State the purpose of
target="_blank"(opens a new tab, keeping the original page available).- Explain the security risk (the new page can access
window.opener).- Show how
rel="noopener"removes that risk.- Justify why internal links should stay in the same tab – it preserves the user’s navigation flow and avoids unnecessary tabs.
anchors.html.styles.css:<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Demo page showing anchor usage">
<meta name="keywords" content="HTML, anchor, link">
<meta name="author" content="Your Name">
<title>Anchor Demo</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
…
<nav><ul>
<li><a href="#home" class="navLink">Home</a></li>
<li><a href="#about" class="navLink">About</a></li>
<li><a href="#contact" class="navLink">Contact</a></li>
</ul>
</nav>
id:<section id="home"><h2>Home</h2>
<p>Welcome to our site.</p>
</section>
<section id="about">
<h2>About</h2>
<p>Information about the project.</p>
<!-- image used as a link to a larger gallery page -->
<a href="gallery.html#photo1">
<img src="thumb1.jpg" alt="View photo 1">
</a>
</section>
<section id="contact">
<h2>Contact</h2>
<p>Email us at <a href="mailto:info@example.com">info@example.com</a>.</p>
<p>Download our brochure: <a href="files/brochure.pdf" download="Brochure.pdf">Brochure</a>.</p>
</section>
<p>Visit <a href="https://www.bbc.com" target="_blank" rel="noopener">BBC News</a> for the latest headlines.</p>
styles.css (use the CSS example from section 8), and open anchors.html in a web browser.Your generous donation helps us continue providing free Cambridge IGCSE & A-Level resources, past papers, syllabus notes, revision questions, and high-quality online tutoring to students across Kenya.