Urgent.News

What's breaking now, across thousands of outlets.

Tech

How to Convert an Image to Base64 (Data URLs): When It Helps and When It Hurts

A data URL lets you embed a file's contents directly in your HTML or CSS instead of linking to a separate file. Images encoded as Base64 are the classic example. It can save a network request, but it also has real downsides, so it pays to know when to use it. What a data URL looks like data:[<media type>];base64,<encoded data> <img src="data:image/png;base64,iVBORw0KGgo..." alt="Icon"> .logo {…

A data URL allows you to embed a file's contents directly in HTML or CSS, rather than linking to a separate file. Images encoded as Base64 are a common example. This can save a network request, but there are also downsides, so it's important to know when to use it.

A data URL looks like data:[media type];base64,encoded data. For instance, an image might be embedded with img src= data:image/png;base64,iVBORw0KGgo... alt=Icon. You can also define CSS backgrounds with background-image: url(data:image/svg+xml;base64,PHN2Zy...);.

To convert an image to a Base64 data URL, choose the image and use a browser-based tool to convert it. Copy the full string, including the data:image/...;base64, prefix, and paste it into the src attribute of an img tag or a CSS url(). After loading the page, verify that the image displays correctly.

Using Base64 helps with tiny images, such as small icons, where saving a network request outweighs the size increase. It's also useful for self-contained HTML files, like emails or single-file reports that must function without external assets. Embedding a placeholder, such as a blurred low-resolution preview, can be beneficial until the full image loads.

However, there are downsides to using Base64. The image size increases by about 33% because 3 bytes become 4 characters. The image cannot be cached separately and is downloaded again every time the HTML or CSS changes. Large data URLs can bloat your HTML or CSS, delaying rendering. Additionally, editing is harder since the image is embedded within the code.

As a rule of thumb, only inline very small images (a few kilobytes at most). For larger images, a normal file on a CDN with caching is faster. Prefer SVG for simple icons, as it can be inlined as plain text without Base64, making it smaller and easier to style.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Cloud Computers for AI Agents in 2026: A Practical Comparison

An AI agent that only talks is cheap to host. The moment it needs to install packages, run tests, start a server, or leave a job running overnight, it needs a computer of its own.

  • Seven providers offer cloud computers for AI agents as of September 26, 2026.
  • Isolation methods include KVM virtual machines, Firecracker microVMs, gVisor, and Linux containers.

Ankita is looking for contributors — here's what you'd actually build

I'm Krish, a developer from India. For the past 8 months I've been building Ankita — a free, open-source desktop AI assistant. Terminal + Electron app, plugin/skill system, local-first by design.

  • Krish developed free, open-source desktop AI assistant Ankita over 8 months
  • App features terminal, Electron, plugin system, local-first design
  • Krish seeks contributors to build real-world Node.js and Electron app

Local-first saves and deciding which copy of the truth wins

Development covered 2 Aug 2026 to 4 Aug 2026 (commit dates). An idle game has to run on the player's device. The loop ticks while they are looking at it, keeps ticking while they are not, and cannot…

  • Game requires authoritative record on player's device
  • Local state can run ahead, but risks losing gains
  • Design artifact: payload fields need maintenance

More from Thursday 1 October →