unDraw for Websites
How to Add an unDraw SVG Illustration to HTML
How to add an unDraw SVG to HTML with an image element or inline SVG, with working code examples, sizing, accessibility basics and the trade-offs of each method.

You have downloaded an illustration from unDraw and now you need it on a web page. There are two main ways to add unDraw SVG to HTML: reference the file with an <img> element, or paste the SVG code directly into your markup so it becomes part of the page. Both are valid, and the right choice depends on whether you need caching, styling control, or animation. This guide walks through both methods with working code, explains the attributes that matter, and finishes with the sizing and accessibility basics that stop an illustration from breaking your layout or excluding your visitors.
One point before the code: always download the file and host it on your own server or project folder. The unDraw license does not allow linking to or embedding the assets straight from the unDraw service, so hotlinking the file from undraw.co is not an option. Download first, then add the local copy to your page. If you have not downloaded anything yet, our guide to downloading unDraw illustrations in SVG and PNG covers choosing the accent color before you save the file.
What you need before you start
SVG is a text based vector format. An unDraw SVG file contains drawing instructions, mostly paths with fill colors, rather than pixels. That is why it stays sharp at any size and why you can open it in a text editor and read the code. The accent color you picked on the unDraw site is written into those fills, so the file already carries your chosen color when you download it.
Keep three things ready before you add unDraw SVG to HTML:
- The downloaded
.svgfile, saved inside your project, for example in animagesorassetsfolder. - A short description of what the illustration shows, which you will use for its text alternative.
- The display size you plan for it, roughly, so you can set sensible width and height attributes.
If you are unsure whether SVG is even the right format for the page you are building, the comparison in unDraw SVG vs PNG walks through the decision in detail.
Method 1: add the SVG with an img element
The simplest and most common approach is to treat the SVG like any other image file. Save it in your project and point an <img> element at it:
<img src="images/team-work.svg"
alt="Two colleagues reviewing charts on a large screen"
width="880" height="620">
That is a complete, working example. The browser requests the file, renders the vector artwork at whatever size your layout gives it, and the illustration stays crisp because there are no pixels to stretch. A few attributes deserve attention:
- src is the path to your local copy of the file. Use a relative path for files inside the same project, or a root relative path such as
/images/team-work.svgon a larger site. - alt is the text alternative. It replaces the image for people who cannot see it and shows if the file fails to load. Write what the illustration communicates, not a list of everything in it. Our guide to writing alt text for unDraw illustrations covers the judgment calls.
- width and height should match the proportions of the artwork. Browsers use these two values to calculate the aspect ratio before the file loads, which reserves the correct space and prevents the page from jumping around as images arrive. The numbers do not have to equal the final display size; the ratio is what matters.
- loading="lazy" tells the browser it may wait until the illustration is near the viewport before fetching it. Use it for artwork below the first screenful, and leave it off the main hero illustration so the top of the page renders quickly.
- decoding="async" lets the browser decode the image without blocking the rest of the page. It is a safe default for illustrations further down the page.
The img method has real advantages. The file is cached separately, so one illustration reused on ten pages downloads once. Your HTML stays small and readable. The trade off is control: the SVG is a sealed picture from the page's point of view, so your CSS cannot reach inside it to change a fill color or animate a single shape. If you need that control, use the second method.
Method 2: paste the SVG inline
Inline SVG means opening the downloaded file in a text editor, copying its code, and pasting it directly into your HTML where the illustration should appear. The file starts with an <svg> element and contains the paths that draw the scene. A shortened version of the pattern looks like this:
<svg viewBox="0 0 880 620" role="img"
aria-labelledby="teamTitle teamDesc"
class="illustration">
<title id="teamTitle">Team work</title>
<desc id="teamDesc">Two colleagues reviewing
charts on a large screen</desc>
<!-- the paths from your downloaded file go here -->
<path fill="#6c63ff" d="..." />
</svg>
Three parts of that example matter. The viewBox attribute defines the internal coordinate system of the artwork; keep the one from your downloaded file exactly as it is, because every path inside was drawn against it. The role="img" attribute with a <title> and <desc> gives the inline artwork an accessible name and description, which is the inline equivalent of the alt attribute. If the illustration is purely decorative, use aria-hidden="true" instead and give it no title, so assistive technology skips it.
The reason to accept the extra markup is styling control. Because the shapes are now part of your document, CSS can target them:
.illustration .accent {
fill: #e75480;
}
That only works if you can identify the shapes, which usually means adding classes to specific paths in an editor or by hand, so expect some tidying work on a detailed scene. Inline SVG also responds well to small touches such as a hover effect or a color change in dark mode. The costs are just as real: the full drawing code is sent with every page that uses it, it cannot be cached as a separate file, and a complex illustration can add a lot of markup to your HTML. For a single hero illustration that you want to recolor or animate, inline is often worth it. For artwork repeated across a site, it usually is not.
A third option: CSS background image
You can also place an SVG as a background through CSS:
.hero {
background-image: url("images/team-work.svg");
background-repeat: no-repeat;
background-size: contain;
}
Reserve this for decoration only. A background image has no text alternative and is ignored by assistive technology, and it will not appear if a visitor prints the page with backgrounds turned off. If the illustration carries meaning, it belongs in the content as an img element or inline SVG, not behind the content as a background.
Which method should you choose?
| Question | img element | Inline SVG |
|---|---|---|
| Reuse the same file on many pages | Best choice, the file is cached | Markup is repeated on every page |
| Change colors with CSS | Not possible | Possible, shape by shape |
| Animate parts of the scene | Only the whole image | Individual shapes can move |
| Text alternative | alt attribute | title and desc elements |
| HTML page weight | Small, image loads separately | Grows with scene complexity |
| Setup effort | One line of markup | Copy, paste, and clean up |
For most pages, the img element is the sensible default: less code, better caching, and no maintenance burden. Reach for inline SVG when the illustration is a centerpiece and you genuinely need to restyle or animate parts of it. Whichever method you pick, the file itself is the same, and you can switch later without downloading anything again.
Sizing the illustration with CSS
An SVG has no fixed pixel size of its own, so tell the browser how it should behave in your layout. The baseline rule for any illustration is:
.illustration {
max-width: 100%;
height: auto;
display: block;
}
max-width: 100% stops the artwork from overflowing a narrow container or a phone screen, height: auto keeps the proportions from the width and height attributes or the viewBox, and display: block removes the small gap browsers leave under inline images. From there you can set an explicit width on a wrapper, for example a two column hero where the illustration takes half the row on desktop and the full width on mobile. The full treatment of fluid sizing, art direction, and srcset lives in our guide to making unDraw illustrations responsive with CSS.
Two sizing mistakes cause most problems. The first is setting both a fixed width and a fixed height that disagree with the artwork's proportions, which stretches the scene. Let one dimension be automatic and the drawing keeps its shape. The second is leaving out width and height attributes entirely, which gives the browser no ratio to reserve and lets the layout shift while the page loads.
Final checks before you publish
- The file is hosted in your own project, not hotlinked from undraw.co.
- The illustration has a text alternative, or is marked decorative on purpose.
- Width and height attributes reflect the real proportions of the artwork.
- The page holds together at phone width, with no horizontal scrolling.
- Below the fold illustrations use lazy loading, and the hero does not.
- If you inlined the SVG, the viewBox is unchanged from the downloaded file.
Once those checks pass, your illustration is part of the page in a way that is fast, stable, and available to every visitor. If page weight becomes a concern as you add more artwork, the techniques in our guide to optimizing unDraw illustrations for faster pages show how to trim SVG code and loading behavior without changing how anything looks.
Recoloring an inline SVG with CSS
One job pushes many people toward the inline method: changing the accent color after the fact. When you download from unDraw, the accent you picked is written into the fills of the drawing. With an img element, that color is final unless you edit the file. Inlined, the shapes sit in your document, and a find and replace on the accent hex value, or a class added to the shapes that carry it, restyles the scene in place. Teams sometimes define the accent as a CSS variable and set the main shapes to use it, so a rebrand touches one line. The full workflow, including recoloring in a vector editor before you inline anything, is covered in our guide to changing an unDraw illustration's color. Keep the change honest, though: the license allows using the artwork in your projects, and recoloring for your own design is part of that use, but the edited file is still unDraw artwork and the license terms about redistribution still apply to it.
Troubleshooting: when the SVG does not appear
When an illustration fails to render, work through the likely causes in this order, because the first two account for most cases:
- The path is wrong. Open the file URL directly in the browser. If it 404s there too, the src points somewhere the file is not. Remember that relative paths resolve against the page's address, which is why root relative paths are safer on larger sites.
- The server sends the wrong content type. SVG should be served as
image/svg+xml. Most modern hosts do this by default; an older or hand rolled server configuration may not, and some browsers then refuse to treat the file as an image. The fix belongs in the server or hosting settings, not in your markup. - The inline copy is damaged. A truncated paste, a missing closing tag, or stray characters introduced by a rich text editor will break an inline SVG while leaving the rest of the page fine. Paste code into a plain text or code editor, and validate the fragment if the browser shows nothing.
- CSS is hiding it. A global rule such as a maximum height, a container with zero width, or a display property inherited from a framework can shrink the artwork to nothing. Inspect the element and read its computed size before blaming the file.
- The file itself is fine but enormous. A very detailed scene pasted inline makes the HTML heavy and the first paint slow. That is the signal to switch that placement back to the img method, where the file caches separately.
Frequently asked questions
Can I link directly to the SVG on undraw.co instead of downloading it?
No. The unDraw license does not permit linking to or embedding the assets from the service. Download the file and host your own copy; that is also what makes your page independent of another site's uptime.
Does inline SVG or the img element load faster?
It depends on reuse. A single small illustration inlined into one page avoids a request. The same illustration on many pages is faster as a separate cached file. Measure your own page rather than following a blanket rule.
Can I animate an unDraw illustration?
With the inline method, yes, within reason: CSS can move or fade individual shapes if you can identify them. Keep motion subtle, and respect visitors who prefer reduced motion by honoring the prefers-reduced-motion setting in your CSS.
