Published by Patrick Mutisya · 14 days ago
By the end of this lesson you will be able to create hyperlinks that:
<a> ElementThe anchor element creates a hyperlink. Its most important attribute is href which defines the destination.
<a href="destination">Link text</a>
Bookmarks are created using the id attribute on any element. The link uses a hash (#) followed by that id.
<h2 id="section2">Section 2</h2>
<a href="#section2">Go to Section 2</a>
Use a relative file path in the href. The path is relative to the current page’s location.
<a href="folder/subpage.html">Open Subpage</a>
Provide the full URL, including the protocol (http:// or https://).
<a href="https://www.bbc.com">BBC News</a>
The mailto: scheme opens the user’s default e‑mail client with the address (and optionally subject or body) pre‑filled.
<a href="mailto:info@example.com">Email us</a>
<a href="mailto:support@example.com?subject=Help%20request">Request Support</a>
target AttributeThe target attribute determines the browsing context.
| Target \cdot alue | Effect | Example |
|---|---|---|
_self | Opens in the same browsing context (default). | <a href="page2.html" target="_self">Same window</a> |
_blank | Opens in a new, unnamed window or tab. | <a href="https://www.wikipedia.org" target="_blank">New tab</a> |
_parent | Opens in the parent frame of the current frame (used with framesets). | <a href="framepage.html" target="_parent">Parent frame</a> |
_top | Opens in the full body of the window, breaking out of any frames. | <a href="toppage.html" target="_top">Full window</a> |
myWindow (any name you choose) | Opens in a named window. If the window does not exist, it is created; otherwise the existing window is reused. | <a href="gallery.html" target="myWindow">Open in MyWindow</a> |
Wrap the <img> element inside an <a> element. (The image itself is not displayed here because external images are prohibited, but the syntax is shown.)
<a href="large-photo.html" target="_blank">
<img src="thumb.jpg" alt="Thumbnail of large photo">
</a>
href (bookmark, file path, URL, or mailto:).id on the target element for same‑page bookmarks.target value for the desired window behaviour.<img> inside the <a> tags.target="_blank" without considering accessibility – always provide clear link text indicating that a new window/tab will open.Create a simple three‑page mini‑website (index.html, about.html, contact.html) with the following features:
info@school.edu with the subject “Inquiry”.src="placeholder.jpg") that links to a larger version of the image in a new tab.Validate the HTML of each page and test all links.