Hyperlinks
The a element and URL anatomy
Skills taught: html.links, html.urls, html.anchor
The **a** element (anchor) creates a hyperlink. The **href** attribute sets the destination URL.
<a href="https://kernal.dhurta.org">Visit KERNAL</a>
URLs in href can be **absolute** (full address) or **relative** (relative to the current page):
<!-- Absolute: full URL including protocol -->
<a href="https://example.com/about">About page</a>
<!-- Relative: from current page location -->
<a href="/about">About page</a> <!-- from root -->
<a href="../about">About page</a> <!-- one folder up -->
<a href="contact.html">Contact</a> <!-- same folder -->
Use **fragment links** (starting with #) to jump to a section on the same page by its id:
<!-- Link to a section -->
<a href="#about">Jump to About</a>
<a href="#contact">Jump to Contact</a>
<!-- The target sections -->
<h2 id="about">About Us</h2>
<p>...</p>
<h2 id="contact">Contact</h2>
<p>...</p>
<!-- Open email client -->
<a href="mailto:hello@dhurta.org">Email us</a>
<!-- Dial phone number -->
<a href="tel:+911234567890">Call us</a>
<!-- Download a file -->
<a href="/files/guide.pdf" download="KERNAL-guide.pdf">Download Guide</a>
Tip:
<a href="https://github.com" target="_blank" rel="noopener noreferrer">
View on GitHub
</a>
Warning:
Frequently Asked Questions
What happens if href is empty or just #?
href="" reloads the page. href="#" scrolls to the top. Use href="#" as a placeholder during development, but replace it before shipping.
Can links wrap block elements like divs?
In HTML5, yes — a is a transparent element and can wrap block-level content. This is commonly used for card components where the entire card is clickable.
What is the difference between relative and absolute URLs?
Absolute URLs include the full protocol and domain (https://example.com/page). Relative URLs are resolved from the current page location (/page resolves from the root; page.html resolves from the current directory).