Sub topic 2
Email, Phone, and Download Links
Assume you know basic HTML structure, can open an HTML file in a browser, and understand file paths. The href attribute tells an anchor element where to go. Some href values use special URL schemes instead of web addresses.
Email, phone, and download links
The mailto: scheme opens the visitor's email application. The tel: scheme opens a phone handler on supported devices. The download attribute suggests saving a same-origin resource instead of navigating to it.
<a href="mailto:[email protected]">Email support</a>
<a href="tel:+15555550123">Call support</a>
<a href="/files/guide.pdf" download>Download the user guide</a>Use visible text that describes the action. A link labeled “Click here” gives little information when read out of context.
Adding images with `img`
The img element embeds an image. src identifies the image file, and alt provides an accessible text alternative.
<img
src="images/red-fox.jpg"
alt="A red fox standing in snow"
width="640"
height="427"
loading="lazy">Writing useful alt text
Write what the image communicates in the current context. Do not begin with “Image of,” because assistive technology already identifies the element as an image. Decorative images should use an empty value: alt="".
If an image is the only content of a link, its alt text should describe the link destination.
<a href="/products/fox-print.html">
<img src="images/fox-print.jpg" alt="View the red fox art print">
</a>Width, height, and lazy loading
width and height let the browser reserve the image's space before the file arrives. This reduces layout shift, which is unexpected movement during loading. Use loading="lazy" for images below the initial viewport when delaying them is useful.
Captions with `figure` and `figcaption`
Use figure for self-contained content and figcaption for its visible caption. The caption does not replace alt; the two serve different purposes.
<figure>
<img
src="images/sales-chart.png"
alt="Sales increased each quarter in 2024"
width="800"
height="450"
loading="lazy">
<figcaption>Quarterly sales, 2024</figcaption>
</figure>Exercise
What should the alt value be for a linked logo that takes visitors to the site's home page?
Show answer
Use destination-based text such as "Example Co. home", because the image is also the link's accessible name.