A data URL embeds file bytes inside a URL string so the browser does not need a second network request. For images that usually means Base64: binary pixels become ASCII that can live in an HTML `src`, a CSS `url()`, or a single-file demo. Inlining is powerful and easy to overuse. This guide covers the anatomy, the size cost, when it wins, when it loses, and how to build strings privately with the Image to Base64 Converter.
Quick answer
Use data URLs for tiny icons, email-safe assets, and self-contained demos. Avoid them for anything large or cacheable - Base64 adds roughly 33% overhead and blocks CDN and browser cache reuse. Prefer a normal image URL for product photos, hero art, and anything shared across pages. Watch Content-Security-Policy: `img-src` and `style-src` may need `data:` allowed.
Data URL anatomy
A data URL has a fixed shape: `data:[media-type][;base64],payload`. For a PNG icon it looks like `data:image/png;base64,iVBORw0KGgo...`. The media type tells the browser how to decode the payload. The optional `;base64` flag means the payload is Base64-encoded binary; without it the payload is URL-encoded text (fine for tiny SVG markup, awkward for photos).
- Scheme - always starts with `data:`.
- Media type - for example `image/png`, `image/jpeg`, `image/webp`, `image/svg+xml`, or `text/css`.
- Encoding flag - `;base64` for binary image bytes; omit for percent-encoded text.
- Payload - the encoded bytes or text after the comma. No spaces; long strings are normal.
Base64 itself is a general encoding (A-Z, a-z, 0-9, +, /, and = padding). The same alphabet carries JSON, tokens, or file bytes. For arbitrary text or files that are not images, use the Base64 Encoder / Decoder. For a local image file turned into a ready-to-paste data URL, use the Image to Base64 Converter - conversion stays in your browser.
The ~33% size penalty
Base64 maps every 3 bytes of binary to 4 ASCII characters. That is a ~33% increase before you count the `data:image/...;base64,` prefix. A 30 KB PNG becomes roughly 40 KB of text in your HTML or CSS. Gzip or Brotli helps a bit on repeated patterns, but they do not erase the tax - and inlined assets cannot be cached separately from the document.
- Binary file - 3 bytes become 4 Base64 characters (~33% larger).
- HTML/CSS bloat - the string ships with every page response that embeds it.
- No independent cache - changing one icon can bust the whole stylesheet or template cache.
- Parse cost - huge attributes and style blocks slow HTML/CSS parsing on weak devices.
When inlining wins
Inlining earns its keep when the alternative is a round trip that costs more than the size tax, or when the environment forbids external files.
- Tiny icons and UI glyphs - a few hundred bytes of PNG or SVG where an extra HTTP request dwarfs the payload.
- Email HTML templates - many clients block or rewrite remote images; a small data URL logo can render without a tracking pixel host.
- Single-file demos and CodePen-style snippets - one HTML file that works offline with no asset folder.
- Critical above-the-fold micro-assets - rare cases where you deliberately avoid a render-blocking image request (measure first).
Rule of thumb: if the asset is under roughly 1-2 KB and used once, a data URL is often fine. If you are unsure, keep it as a file and measure.
When inlining loses
- Anything cacheable across pages - logos, sprites, and shared icons belong in files (or a sprite/SVG system) so the browser downloads them once.
- Anything large - photos, illustrations, and hero images blow up HTML/CSS and hurt First Contentful Paint.
- Assets that change independently - you do not want to republish a 200 KB stylesheet because one favicon changed.
- HTTP/2 or HTTP/3 sites with good caching - parallel requests are cheap; the old "avoid every request" advice is weaker than it was on HTTP/1.1.
Prefer files for real imagery
Product shots, blog figures, and marketing heroes should stay as `.webp` / `.avif` / `.png` URLs with proper `width`, `height`, and caching headers. Use data URLs for glue, not for the gallery.
HTML img and CSS background-image
In HTML, paste the full data URL into `src`:
- `<img src="data:image/png;base64,..." alt="..." width="16" height="16">` - keep alt text; set dimensions so layout does not jump.
- Inline SVG as `data:image/svg+xml,...` works, but raw `<svg>` in the document is often clearer and more accessible.
- Do not put megabyte-scale strings in `src` - the DOM attribute alone becomes painful to edit and ship.
In CSS, the same string goes inside `url()`:
- background-image: url("data:image/png;base64,...");
- Works for `background`, `list-style-image`, and `mask-image` the same way.
- After you generate CSS that embeds data URLs, you can still run the stylesheet through the CSS Minifier to strip comments and waste whitespace - minification does not shrink Base64 much, but it cleans the rest of the file.
CSP and caching caveats
Content-Security-Policy often blocks `data:` by default for images or styles. If icons vanish after you tighten CSP, check `img-src` (and `style-src` / `style-src-elem` if you use data URLs inside stylesheets). Allowing `data:` widens the attack surface slightly - prefer external files when CSP must stay strict.
- Caching - inlined bytes inherit the cache lifetime of the HTML or CSS document. You lose per-asset `Cache-Control` and CDN edge caching.
- Service workers - a huge HTML shell with embedded images is harder to update surgically than a small HTML file plus hashed assets.
- Email - data URLs help some clients and fail in others; always test major clients before shipping a campaign.
- Privacy - converting locally with ToolsMinify means the image never uploads. That matters for screenshots and unreleased UI.
Frequently asked questions
Is Base64 encryption?
No. Base64 is encoding, not encryption. Anyone can decode it. Do not put secrets in data URLs.
Should I inline my site logo as a data URL?
Usually no if the logo appears on many pages. A cached `/logo.svg` downloads once. Inline only if the logo is tiny and used in a one-off context (for example a single email).
Do data URLs help Core Web Vitals?
Sometimes for a single tiny critical icon; often they hurt when they inflate HTML. Measure LCP and page weight before and after. Large inlined heroes are a common regression.
Can I convert an image to a data URL without uploading it?
Yes. The Image to Base64 Converter reads the file in your browser and outputs a data URL or raw Base64. Nothing is sent to a server.
What about SVG - Base64 or raw markup?
Inline SVG markup in HTML is usually better for accessibility and styling. Use a data URL when you must drop SVG into a context that only accepts a URL (some CSS properties, some email paths).
Convert images on ToolsMinify
Every tool below runs in your browser - free, no signup, nothing uploaded:
- Image to Base64 Converter - turn a local image into a data URL or Base64 string for HTML and CSS.
- Base64 Encoder / Decoder - encode or decode arbitrary text and non-image payloads.
- CSS Minifier - shrink stylesheets that embed small data URL backgrounds.
- All developer tools - the full category index.
Try it free
Open the Image to Base64 Converter, pick a tiny PNG or SVG, copy the data URL, and paste it into an `img` src or CSS `url()`. Everything stays on your device.