Skip to main content
How-to

How to Add an Inline Diagram to a Page (Step-by-Step)

By ยท Updated ยท 4 read

Overview

A working pattern for adding your first inline SVG diagram with full schema, accessibility, and brand styling. Once you do this once, every additional diagram is a 5-minute extension of the same pattern.

Step 1: Decide what to visualize

The diagram should answer a specific question the reader implicitly has. Examples: "how do these three concepts relate?" (Venn or 2ร—2), "what are the steps?" (flowchart), "what's the hierarchy?" (pyramid or tree), "how big is each part?" (pie or bar chart).

Don't add a diagram for decoration. Diagrams that don't answer a question dilute the page's quality signal rather than enhance it.

Step 2: Sketch the diagram

On paper or in a quick draw tool, sketch the structure. Identify: the elements (shapes), the labels, the relationships (arrows, lines, containment), and the visual hierarchy (what should be biggest/loudest).

Keep labels short โ€” 1-3 words each. Long labels overflow on mobile.

Step 3: Write the SVG

Use a `viewBox` (e.g., `viewBox="0 0 800 400"`) so the diagram scales. Set `width="100%" height="auto"` on the `<svg>` for responsive sizing.

Use brand-palette colors only. Stroke widths of 2px for lines, 4-8px for accent strokes. Text at 11-14px.

Add `role="img"` and `aria-labelledby` on the `<svg>` element pointing at the IDs of a `<title>` and `<desc>` element you place as the first children of the SVG.

Step 4: Wrap with figure + figcaption

Wrap the `<svg>` in a `<figure>` with a `<figcaption>` below. The figcaption is a one-sentence human-readable summary of what the diagram shows. This appears below the diagram in the rendered page.

Step 5: Add ImageObject schema to page head

Add a `<script type="application/ld+json">` block to the page `<head>` (or via your CMS's schema slot) containing an `ImageObject` schema. Required fields: `name` (short title for the diagram, matching the figcaption), `description` (longer explanation), `contentUrl` (the page URL plus an anchor for the diagram).

Step 6: Test

Open the page in your browser at desktop width and verify the diagram renders correctly. Resize to 320px to check mobile. Use a screen reader to verify the title and description are read out. Validate the ImageObject schema with Google's Rich Results Test.

Frequently asked questions

What if I can't write SVG by hand?

Tools like Figma can export SVG, but the exported SVG is often bloated with redundant attributes. Hand-coding from a sketch is usually cleaner and easier than exporting then cleaning. Start with simple shapes (rect, circle, line, text) โ€” you don't need complex paths for most diagrams.

How long should it take to add one diagram?

First diagram: 30-60 minutes including learning the pattern. Tenth diagram: 5-10 minutes for a similar-complexity diagram. The pattern is the same every time; only the content varies.

Can I use a JavaScript chart library instead?

Yes, but only when the data is genuinely dynamic. For static diagrams, inline SVG is better โ€” chart libraries add 50-200KB of JS for what could be a 2KB SVG. Pick the lighter option when it works.

MG
Written by

Matt is the founder of RunOctopus. He built All Angles Creatures from zero to page-1 rankings in reptile feeder insects in under 60 days using exactly this method โ€” turning a hard, entrenched niche into RunOctopus's proof store for programmatic SEO and AI search citation.

Connect on LinkedIn →

See what Otto would build for your store

Free architecture preview. No card required. Five minutes.

Generate Preview →