01 — The question
The question
Learning outcomes
By the end of this lesson, you can choose between img, svg, canvas and math; give each graphic a text alternative; and explain why object and embed are rarely the right choice on a new page.
02 — The idea
The idea
Terminology
canvas: a bitmap surface that script draws on. The pixels are not elements, so the content is not in the document structure.
svg: an XML vector graphic that can appear inline in HTML or as an image file.
math: MathML, the markup for mathematical notation.
object, embed, param: older elements for external content. Use them only when no better element fits.
Choose the simplest element
Most graphics are img with alt text, or svg for a vector drawing or icon. Use canvas only when you need pixel-level drawing controlled by script, such as a chart generated in the browser. Use math for formulas, because screen readers and browsers can read the structure of the notation.
Canvas needs an alternative
Canvas pixels are invisible to assistive technology. Put a text alternative in the content between canvas tags, which browsers that cannot draw canvas show, and describe the drawing in nearby text. The fallback content is also what you should check when canvas is unsupported.
Inline SVG
An svg element can sit in the HTML. Give it role="img" and a title, and point aria-labelledby at the title, so the graphic has a name. A decorative icon gets aria-hidden="true" instead, because its meaning is carried by nearby text.
object, embed and param
object loads an external resource and can hold fallback content. embed loads a plug-in or external application and has no fallback content. param passes settings to object. These elements depend on the browser handling the resource type. For PDFs, video, audio or images, a link, img, video or iframe is clearer and more reliable.
03 — Worked example
Worked example
An accessible inline icon and a chart fallback
The first example is an informative inline graphic with a name. The second is a canvas with its alternative inside.
Change the code, then look at the preview. The preview runs in a sandbox.
Run the code to see the preview.
The preview appears here.
Formulas with MathML
MathML describes the structure of a formula, so a fraction is a fraction rather than a line of characters. A simple half is shown below.
Change the code, then look at the preview. The preview runs in a sandbox.
Run the code to see the preview.
The preview appears here.
04 — Try it
Try it
Tiered exercises
Work through the levels in order.
Level 1: choose
For a logo, a vector icon, a browser-drawn bar chart and a quadratic formula, name the element you would use and why.
Level 2: name
Make the inline icon from the example informative, with a name that is read by assistive technology. Then make a second copy decorative.
Level 3: replace
Replace an embed of a PDF with a link. Explain what the user loses, if anything, and what they gain.
Complete solutions
05 — Check yourself
Check yourself
Recap and exit questions
Choose the simplest element. Canvas needs a text alternative, inline SVG needs a name or a hidden state, MathML carries formulas, and object and embed are rarely the right choice.
06 — What’s next
What’s next
Official references
MDN: canvas element
MDN: SVG in HTML
MDN: MathML
MDN: object element
MDN: embed element
WCAG 2.2: Non-text Content
The idea to take with you
Choose the simplest element that fits. img and svg cover most graphics, canvas is a script-drawn bitmap that needs a text alternative, MathML carries formulas, and object and embed are rarely the right choice in new pages.
A small marker for this page. Sign in to save your progress.