HTML Links
Subject: html
HTML Links
Links (or hyperlinks) are a core component of the web, enabling users to navigate across pages, documents, or resources. The anchor tag (<a>
) is used to create these interactive elements.
π What Is an HTML Link?
An HTML link connects one document to another. It's defined using the <a>
tag and usually includes the href
attribute to specify the destination.
Syntax:
href
: The URL or file to navigate toLink Text
: The visible clickable text or content
Example:
π¨ Default Browser Styles
- Unvisited links: Blue & underlined
- Visited links: Purple & underlined
- Active links: Red & underlined
You can override these with CSS:
πͺ The target
Attribute
The target
attribute controls where the linked page opens:
_blank
: Opens in a new tab or window_self
: Opens in the same tab (default)_parent
: Opens in the parent frame_top
: Opens in the full body of the window
Example:
π Absolute vs Relative URLs
- Absolute URL: Full address with domain β for external sites
- Relative URL: Relative path within your site
πΌοΈ Using Images as Links
Make any image clickable by wrapping it in an <a>
tag:
π§ Email Links with mailto:
Open the userβs email client with a pre-filled address:
With subject and body:
π§ Buttons as Links (JavaScript)
You can use a <button>
to behave like a link:
π·οΈ Add Tooltips with title
Attribute
Provide extra info on hover for accessibility:
β Key Takeaways
- Use
<a href="...">
to create links - Use absolute URLs for external links and relative URLs for internal ones
- Use
target="_blank"
for new tabs - Wrap images in
<a>
to create clickable graphics - Use
mailto:
for email actions - Add
title
for accessibility and JavaScript for dynamic navigation
Advertisement Slot 1
Advertisement Slot 2