Figures, captions and image links: give pictures context
Group a picture with its visible caption, explain how captions differ from alt text, and make a picture into a useful link without losing a clear destination name.
In a printed lab record, a drawing and its label form one unit. The main explanation can refer to that drawing without mixing its label into an unrelated paragraph. HTML offers a similar group through figure.
A figure is self-contained content, optionally with a caption, that is treated as one unit. It can contain an image, a diagram, a code example or other suitable content. Not every image needs figure: a tiny decorative mark beside a sentence usually does not form such a unit.
Figure and figcaption
HTML fragment — part of a document
<figure><imgsrc="images/study-desk.svg"alt="A notebook and pencil on a study desk"width="360"height="220"><figcaption>Two items for the first writing exercise.</figcaption></figure>
The figcaption element gives the figure a visible caption. It must be the first or last child of its figure, and a figure has at most one direct figcaption. Place it before the content for a caption at the beginning, or after for a caption at the end. It does not belong outside the figure just because it looks close on the screen.
Browsers often add margins around figure. Those are default styles, not a requirement to create a wide blank border. CSS can adjust the appearance later.
Complete program: desk-figure.html
Use the supplied images folder from the example ZIP.
desk-figure.html
<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><title>A Figure for the Writing Exercise</title></head><body><h1>Set up the writing exercise</h1><p>The figure groups the desk drawing with its explanation.</p><figure><imgsrc="images/study-desk.svg"alt="A notebook and pencil on a study desk"width="360"height="220"><figcaption>Two items for the first writing exercise.</figcaption></figure><p>Write one sentence in the notebook before opening another example.</p></body></html>
Browser previewDocument title: A Figure for the Writing Exercise
This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.
Expected result: a drawing and its caption appear together between two paragraphs. The caption is real page text. If you copy only the img into another page, the caption does not move automatically; keep the complete figure when that context matters.
Caption and alt are different
A caption is visible context for the figure. It can explain why the figure matters, give it a label or include appropriate credit. Alt is replacement text for the image's useful purpose when it cannot be seen.
Avoid making someone hear exactly the same long sentence twice through duplicated alt and caption. Write each for its job. In the example, alt identifies the depicted items and caption explains how they belong to the exercise.
Sometimes the nearby text already provides a fully equivalent explanation and the image adds nothing beyond it. Empty alt can then be appropriate, but the mere presence of a caption does not make every image decorative. Check what information would be lost without the picture. A caption saying Figure 1 is not an adequate replacement for an important chart.
Question
Where the answer usually belongs
What useful image information needs a text replacement?
Img alt and, for complex content, a fuller explanation
What visible context names or explains the figure?
Figcaption
Where should this link take the reader?
The link's accessible name, supplied by text or suitable image alt
Turn an image into a link
Put img inside an a with href. The anchor supplies navigation; the image supplies the linked content. Do not put href on img and expect the image element to become a link by itself.
HTML fragment — part of a document
<ahref="#practice"><imgsrc="images/study-desk.svg"alt="Go to the notebook practice task"width="360"height="220"></a>
When an image is the only content of a link, its alt should explain the link's purpose, rather than only the picture's appearance. Here, Go to the notebook practice task is more useful than A desk. A keyboard user can focus the anchor and press Enter just as with a text link.
Keep the three jobs clear
1Figure: the content unit
2Figcaption: visible context
3Img alt: useful replacement text
4Anchor: the linked destination
A caption does not automatically make an image decorative. An image-only link needs a meaningful name.
Complete program: image-navigation.html
image-navigation.html
<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><title>Picture Link to a Practice Task</title></head><body><h1>Choose the notebook task</h1><figure><ahref="#practice"><imgsrc="images/study-desk.svg"alt="Go to the notebook practice task"width="360"height="220"></a><figcaption>The desk drawing links to the task below.</figcaption></figure><p><ahref="#practice">Read the notebook practice task</a></p><h2id="practice">Notebook practice task</h2><p>Write a heading and two sentences for a fictional college notice.</p></body></html>
Browser previewDocument title: Picture Link to a Practice Task
This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.
Expected result: the picture is clickable and a separate visible text shortcut offers the same destination. Both lead to the practice heading. On a short page, there may be little room to scroll; check the fragment in your saved page's address as well.
Image and text inside one link
If a link already contains clear visible text, a decorative icon within that same link can use empty alt. The text then names the link. Do not use empty alt on an image-only link unless another suitable accessible name is deliberately provided; otherwise the control may have no useful name.
HTML fragment — part of a document
<ahref="#practice"><imgsrc="images/practice-mark.svg"alt=""width="40"height="40">
Read the notebook practice task
</a>
Avoid two adjacent separate links to the same destination when one combined image-and-text link would be clearer. The complete program intentionally includes a separate shortcut to let you compare text-link and image-link behaviour; it is not a rule to duplicate every link.
Large image links and older techniques
An image link can lead to a larger image file. Write a label such as Open the full-size desk drawing and warn about unusually large downloads when relevant. It still follows ordinary href and target rules.
Do not add obsolete border="0" to remove an image-link border. Use CSS when styling is needed. Do not put a button or another anchor inside the link. Clickable regions within one image use an image map, a separate topic later; most beginner pages are clearer with ordinary links and visible labels.
Problem and solution: the picture link has no name
Problem: a student wraps a decorative img with alt="" in a link, removes the visible link words and expects everyone to understand the destination from the drawing.
Solution: add meaningful visible link text, or provide suitable alt for an image-only link. Then navigate with Tab and check that the focused control has a clear purpose. A filename, surrounding visual position or mouse cursor is not a dependable replacement for a link name.
Common mistakes and useful tips
Using figcaption outside its figure.
Placing several direct captions inside one figure.
Assuming every caption removes the need for an alt decision.
Putting href on img instead of wrapping it in an anchor.
Describing only appearance when the image is the link's only label.
Giving an image-only link empty alt and no other useful name.
Removing keyboard focus styles when making the picture look clickable.
Forgetting to supply the image file with the saved HTML example.
Practice questions
What does figure group?
Where can a figcaption appear inside its figure?
How does alt differ from a visible caption?
Which element supplies navigation for a linked image?
What should alt describe when the image is the link's only content?
Build a page with a captioned figure and an image link to a practice section. Test the destination with both the mouse and keyboard, and explain each alt choice.
Check your practice answers
Self-contained content treated as one unit, optionally with a caption.
As its first or last child, with at most one direct figcaption.
Alt replaces useful image information. A caption supplies visible context for the figure. Their jobs can overlap, but they should not be confused or needlessly duplicated.
An a element with href, wrapping the image.
The link's purpose or destination, so someone who cannot see the picture still knows what activating it does.
Supply the image, use a unique destination id and match its fragment. Choose functional alt for an image-only link or visible text with a decorative image inside the same link. Check Tab, Enter and the destination.
Interview questions
Does every image belong in figure?
No. Figure is useful when content forms a self-contained unit, often with a caption. Inline decorations and ordinary images do not automatically need that grouping.
Does a figcaption replace img alt?
Not automatically. Decide what information the image contributes and what replacement is needed. A caption might explain context without describing the important image information.
How do you make an image-only link understandable?
Give the image suitable alt that names the destination or action. Ensure the anchor has a real href and remains keyboard accessible. Do not leave it unnamed with empty alt.
Can a linked decorative image have empty alt?
Yes, when clear text within the same link already provides the link name. Empty alt avoids repeating irrelevant decoration. That differs from an image-only link with no other name.
Quick revision
Figure groups a meaningful unit; figcaption labels that unit visibly.
Place one direct caption first or last.
Alt, caption and link purpose each need a deliberate decision.
Wrap an image in a named, keyboard-accessible anchor to link it.