{"id":148,"date":"2026-10-18T21:10:26","date_gmt":"2026-10-18T21:10:26","guid":{"rendered":"https:\/\/refracttools.com\/blog\/?p=148"},"modified":"2026-10-18T21:10:26","modified_gmt":"2026-10-18T21:10:26","slug":"base64-images","status":"publish","type":"post","link":"https:\/\/refracttools.com\/blog\/performance\/base64-images\/","title":{"rendered":"Base64 images: when to inline them (and when not to)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Use Base64 images only for very small files, roughly under 10 KB: icons, a tiny logo, a blurred placeholder, or images in HTML email. Base64 text is about 33% larger than the original file, it can&#8217;t be cached separately from the CSS or HTML it sits in, and a large data URI in a stylesheet delays rendering until the whole stylesheet has downloaded. For anything bigger, a normal image file with good caching is faster.<\/p>\n\n\n\n<div class=\"wp-block-group is-style-refract-takeaways is-layout-constrained wp-block-group-is-layout-constrained\">\n<h3 class=\"wp-block-heading\">Key takeaways<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Base64 turns every 3 bytes into 4 characters, so the encoded text is about a third bigger.<\/li>\n\n\n<li>Gzip and Brotli win most of that back in transfer, but not the caching and render-blocking costs.<\/li>\n\n\n<li>Good uses: tiny icons, placeholders, email, single-file demos. Bad uses: photos, hero images, anything reused across pages.<\/li>\n\n\n<li>SVG doesn&#8217;t need Base64 at all; URL-encoding it is shorter.<\/li>\n<\/ul>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">What is a Base64 image?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Base64 writes binary data using only 64 safe characters: A\u2013Z, a\u2013z, 0\u20139, plus and slash. Wrapped in a data URI, an entire image can live inside your HTML or CSS as text:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;img src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAA\u2026\" alt=\"\"&gt;\n\n.icon {\n  background-image: url(\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAA\u2026\");\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The browser decodes the text back into the image without making a separate request for it. You&#8217;ll find data URIs in plenty of themes, plugins and email templates, often added automatically by build tools that inline anything below a size threshold. That saving was a big deal when every HTTP request was expensive. With HTTP\/2 and HTTP\/3 sending many files over one connection, it matters far less.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How much bigger does Base64 make an image?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Every 3 bytes of the file become 4 characters, so the encoded text is about 4\/3 the size of the original. Compression on the server (gzip or Brotli) claws much of that back, because Base64 text is very repetitive in its use of characters. I measured two images in the browser:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><div class=\"table-scroll\" tabindex=\"0\" role=\"region\" aria-label=\"Scrollable table\"><table><thead><tr><th>Image<\/th><th>Original file<\/th><th>Base64 text<\/th><th>Base64, gzipped<\/th><\/tr><\/thead><tbody><tr><td>32\u00d732 PNG icon<\/td><td>559 bytes<\/td><td>748 bytes<\/td><td>602 bytes<\/td><\/tr><tr><td>1600\u00d7900 JPEG<\/td><td>92,872 bytes<\/td><td>123,832 bytes<\/td><td>85,364 bytes<\/td><\/tr><\/tbody><\/table><\/div><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So over the network, a Base64 image inside a gzipped stylesheet costs about the same bytes as the file itself. The size penalty isn&#8217;t really the problem. These are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>No separate caching.<\/strong> An image file is cached once and reused on every page. Inlined, it is downloaded again inside every HTML page, or the whole stylesheet has to be re-downloaded whenever any rule changes.<\/li>\n\n\n<li><strong>Render blocking.<\/strong> CSS blocks rendering until it has fully downloaded. A 100 KB image inside it holds up the whole page, even if that image is below the fold.<\/li>\n\n\n<li><strong>No lazy loading or responsive sizes.<\/strong> You lose <code>loading=\"lazy\"<\/code>, <code>srcset<\/code> and format negotiation, so phones download the same image as desktops.<\/li>\n\n\n<li><strong>Decoding cost.<\/strong> The browser has to parse the long string and decode it before it can show the image.<\/li>\n<\/ul>\n\n\n<aside class=\"tool-card tool-card--inline\"><span class=\"swatch\" style=\"background:linear-gradient(135deg,#5ce1c6,#13161c)\" aria-hidden=\"true\"><\/span><div class=\"tool-card__body\"><p class=\"tool-card__eyebrow\">Free tool<\/p><p class=\"tool-card__name\">Image to Base64 converter<\/p><p class=\"tool-card__blurb\">Encode images as data URIs for CSS and HTML, or decode them back.<\/p><\/div><a class=\"btn primary\" href=\"https:\/\/refracttools.com\/image-to-base64\/\">Try it free <span aria-hidden=\"true\">\u2192<\/span><\/a><\/aside>\n\n\n\n<h2 class=\"wp-block-heading\">When should you use Base64 images?<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><div class=\"table-scroll\" tabindex=\"0\" role=\"region\" aria-label=\"Scrollable table\"><table><thead><tr><th>Use it for<\/th><th>Avoid it for<\/th><\/tr><\/thead><tbody><tr><td>Tiny icons (a few hundred bytes to a few KB)<\/td><td>Photos and hero images<\/td><\/tr><tr><td>Blurred image placeholders<\/td><td>Images used on many pages<\/td><\/tr><tr><td>HTML emails, where linked images are often blocked<\/td><td>Anything over about 10 KB<\/td><\/tr><tr><td>Single-file demos and offline HTML pages<\/td><td>Images that need srcset or lazy loading<\/td><\/tr><tr><td>Favicons in a quick prototype<\/td><td>Your production favicon set<\/td><\/tr><\/tbody><\/table><\/div><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Placeholders are the best everyday use. A tiny blurred placeholder of a few hundred bytes, inlined as a data URI, can show instantly while the real image loads. See <a href=\"\/blog\/performance\/blurhash-vs-lqip\/\">BlurHash vs LQIP<\/a> and the <a href=\"https:\/\/refracttools.com\/blur-placeholder-generator\/\">blur placeholder generator<\/a>.<\/p>\n\n\n\n<div class=\"wp-block-group is-style-refract-callout is-layout-constrained wp-block-group-is-layout-constrained\">\n<p class=\"wp-block-paragraph\"><strong>Email:<\/strong> Email clients often block remote images until the reader allows them, and several popular clients, Gmail among them, don&#8217;t display data URI images reliably. Test in the clients your audience uses before relying on Base64 in email.<\/p>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">What about SVG?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">SVG is already text, so encoding it in Base64 makes it bigger and unreadable for no benefit. URL-encode it instead: only a few characters, such as <code>#<\/code>, <code>&lt;<\/code>, <code>&gt;<\/code> and <code>%<\/code>, need escaping. The result is usually shorter than Base64 and compresses better. The <a href=\"https:\/\/refracttools.com\/svg-to-css\/\">SVG to CSS converter<\/a> does that for you, and our guide to <a href=\"\/blog\/css-techniques\/svg-data-uri-css\/\">SVG data URIs in CSS<\/a> explains the details.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How do you find Base64 images slowing a page down?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Open your browser&#8217;s developer tools and look at the size of your CSS and HTML files in the Network panel. A stylesheet that is hundreds of kilobytes for a modest site often has images or fonts inlined. Search the file for <code>base64,<\/code> to find them. Lighthouse also flags render-blocking stylesheets, and page builders and plugins are a common source: some inline icons, fonts or background images automatically. Moving a large inlined image back to a normal file, served at the right size with <a href=\"\/blog\/performance\/srcset-sizes-explained\/\">srcset and sizes<\/a>, usually improves the first paint straight away.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How do you convert Base64 back to an image?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Paste the Base64 string or full data URI into the decoder side of the <a href=\"https:\/\/refracttools.com\/image-to-base64\/\">image to Base64 converter<\/a>. It detects the format, previews the image and lets you download the file. This is handy when you find an image buried in someone else&#8217;s CSS, an API response or an email source.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Convert an image<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Drop images into the <a href=\"https:\/\/refracttools.com\/image-to-base64\/\">image to Base64 converter<\/a> and choose the output: a plain data URI, a CSS background rule, an HTML img tag, Markdown or the raw Base64. Everything runs in your browser. Before inlining anything, shrink it: compress photos with the <a href=\"https:\/\/refracttools.com\/compress-image-to-size\/\">compress to size tool<\/a> and clean SVGs with the <a href=\"https:\/\/refracttools.com\/svg-optimiser\/\">SVG optimiser<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Last checked: October 2026.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Sources: <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/URI\/Reference\/Schemes\/data\" rel=\"noopener\" target=\"_blank\">MDN: data: URLs<\/a>, <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Glossary\/Base64\" rel=\"noopener\" target=\"_blank\">MDN: Base64<\/a>, <a href=\"https:\/\/developer.chrome.com\/docs\/lighthouse\/performance\/render-blocking-resources\" rel=\"noopener\" target=\"_blank\">web.dev: Render-blocking resources<\/a>.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Base64 data URIs save a request but cost caching, lazy loading and render speed. Measured sizes, the cases where inlining helps, and why SVG should be URL-encoded instead.<\/p>\n","protected":false},"author":1,"featured_media":147,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_refract_tool":"image-to-base64","footnotes":""},"categories":[36],"tags":[5,17],"class_list":["post-148","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-performance","tag-image-tools","tag-performance"],"_links":{"self":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts\/148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/comments?post=148"}],"version-history":[{"count":1,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts\/148\/revisions"}],"predecessor-version":[{"id":164,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/posts\/148\/revisions\/164"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/media\/147"}],"wp:attachment":[{"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/media?parent=148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/categories?post=148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/refracttools.com\/blog\/wp-json\/wp\/v2\/tags?post=148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}