Links and Images
The real power of the World Wide Web comes from hyperlinks that connect documents across the globe, combined with rich visual media. In HTML, the anchor element (<a>) creates links, while the image element (<img>) displays graphical assets.
Creating Hyperlinks with the Anchor Tag
The anchor tag uses the href attribute (Hypertext Reference) to specify where the link points. You can navigate between internal pages of your own site or connect to external resources on other domains.
<!-- External link -->
<a href="https://developer.mozilla.org" target="_blank" rel="noopener noreferrer">
Visit MDN Web Docs
</a>
<!-- Relative link to a local page -->
<a href="/about.html">About Our Project</a>
When linking externally with target="_blank", always add rel="noopener noreferrer" to protect security and performance.
Embedding Accessible Images
The <img> tag is a void (self-closing) element. It requires two fundamental attributes:
src: The source location of the image file (URL or relative path).alt: The alternative text description that displays if the image fails to load and is announced to visually impaired users by screen readers.
<img src="/images/mountain.jpg" alt="Snow-capped mountain peaks during sunrise" width="600" height="400" />
Writing descriptive alt text is a strict accessibility requirement. Never leave alt text empty unless the image is purely decorative, in which case an empty string (alt="") tells assistive devices to skip it.
Relative vs Absolute Paths
- Absolute paths provide the full protocol and domain (e.g.,
https://example.com/logo.png). - Relative paths point to files in relation to the current document (e.g.,
./assets/photo.jpgor../styles.css).
Key takeaways
- Anchor (
<a>) tags connect pages using the requiredhrefattribute. - Use
rel="noopener noreferrer"whenever opening external links in a new tab. - Every
<img>element must include a descriptivealtattribute for accessibility. - Choose relative paths for internal assets and absolute URLs for external resources.