Part 3: Links, Images, and Media
Introduction
Links are what make HTML "hyper" β the ability to connect documents together is the foundation of the entire web. Images and media are often half the information on a page. These elements look simple on the surface, but getting them right β accessible alt text, correct URL strategies, responsive images, lazy loading β makes a material difference in usability and performance.
This part covers everything I know from writing links and embedding media in real pages.
The Anchor Element (<a>)
<a>)The <a> tag creates a hyperlink. It can link to other pages, external sites, sections of the same page, email addresses, phone numbers, or trigger file downloads.
Basic Link
<a href="https://github.com/Htunn/simple-waf-scanner">View on GitHub</a>The href attribute (Hypertext REFerence) contains the destination URL. The link text should describe where the link goes β not "click here" or "read more".
Absolute vs. Relative URLs
Absolute URLs
Include the full protocol, domain, and path. Required for external links.
<a href="https://crates.io/crates/simple-waf-scanner">View on crates.io</a>Relative URLs
Relative to the current document's location.
https://...
External links always
./page.html
Same directory (explicit)
../page.html
Parent directory
/path/page.html
Root-relative, consistent regardless of current location
For internal links within a project or site, root-relative paths (/path/to/page) are the most reliable. They do not break when files are moved between directories.
Linking to Page Sections (Fragment Identifiers)
Any element with an id attribute can be linked to directly:
This is how table-of-contents links in documentation work.
Opening Links in a New Tab
target="_blank" opens the link in a new tab or window.
rel="noopener noreferrer" is required for security. Without noopener, the opened page can access and manipulate the original page via window.opener. noreferrer additionally suppresses the Referer HTTP header.
When to use new tabs: External links where users are expected to reference while staying on the current page. Do not use it for internal navigation β it is disorienting and breaks the back button.
Email and Phone Links
mailto: opens the user's default email client. tel: triggers the phone dialler on mobile.
Download Links
The download attribute tells the browser to download the file rather than navigate to it. Optionally provide a suggested filename.
The Image Element (<img>)
<img>)<img> is a void element. The two essential attributes are:
srcβ the path to the image filealtβ alternative text
Writing Good Alt Text
Alt text is read by screen readers and displayed when the image fails to load. Writing it well is not optional.
Informative images β describe what the image shows and why it matters:
Decorative images β provide an empty alt attribute so screen readers skip them:
Never: leave alt text out entirely (inaccessible), use "image of..." (the screen reader already announces it is an image), or just write the filename.
Image Width and Height
Always specify width and height:
This reserves the correct space in the layout before the image loads, preventing layout shift β the page jumping around as images load. This directly affects Core Web Vitals scores (CLS β Cumulative Layout Shift).
Responsive Images
For images that should adapt to different screen sizes, use srcset and sizes:
srcsetlists available image files with their intrinsic widthssizestells the browser which size to expect at different viewport widthsThe browser picks the most appropriate file, saving bandwidth on smaller screens
Lazy Loading
Defer loading off-screen images until the user scrolls to them:
Do not lazy-load images that are visible in the initial viewport (above the fold) β that delays the most visible content.
The <picture> Element
<picture> Element<picture> allows serving different image formats or completely different images based on conditions:
The browser uses the first <source> it can handle and ignores the rest. The <img> is the fallback and carries the alt text.
Figures with Captions
<figure> wraps self-contained content (images, diagrams, code examples) and <figcaption> provides a visible caption. The caption and alt text serve different purposes: alt is for when the image cannot be seen; caption is supplementary information for everyone.
Tables
Tables are for tabular data β information that has a natural row/column structure. Do not use tables for layout.
Key elements:
<caption>β visible table title, announced by screen readers<thead>/<tbody>/<tfoot>β semantic grouping of rows<th scope="col|row">β header cells withscopefor accessibility<td>β data cellscolspan/rowspanβ span across columns or rows
Video
With multiple source formats for browser compatibility:
controlsβ shows play/pause/volume controlsposterβ image displayed before playback startspreload="metadata"β loads only metadata (duration, dimensions), not the full video
Audio
Summary
<a href="">
Hyperlinks β internal, external, fragments, email, tel
target="_blank" rel="noopener noreferrer"
Open in new tab safely
download attribute
Trigger file download
<img src="" alt="">
Embed images with meaningful alt text
width / height on <img>
Prevent layout shift
loading="lazy"
Defer off-screen images
srcset / sizes
Serve appropriately sized images
<picture>
Serve different formats or art-directed images
<figure> / <figcaption>
Self-contained media with visible caption
<table>
Tabular data (not layout)
<video> / <audio>
Native media embedding with controls
Up Next
Part 4 covers forms and user input β the HTML elements that collect data from users.
Last updated