A Cross-Browser Method for Embedding Images in Self-Contained HTML Documents

An exploration of encoding image data directly into DHTML files — a lightweight, freely editable alternative to PDF that works across Netscape, Mozilla, Firefox, and Internet Explorer.

View the demo
A grainy black-and-white film photograph of a printed technical document lying on a light wooden desk, soft window light

Author's note, March 18, 2007: This article was written almost a year after originally developing the technique described here. The approach is now going on three years old. It's just plain silly that there still isn't a better way. —BPH

The technique of embedding images directly into HTML documents began as a workaround for an era when browser support for self-contained file formats was inconsistent. By encoding image data as a base64 string within the source code, developers could create a single file that displayed both text and visuals without relying on external assets. This approach proved especially useful for sharing documents across different operating systems and browser versions, where linked images often broke or failed to load. Although modern browsers have since adopted more standardized methods, the early experiments with cross-browser embedding highlighted the value of portability and independence from server dependencies.

Self-contained HTML documents offered a lightweight alternative to proprietary formats like PDF, particularly for projects that required easy editing and redistribution. By incorporating images directly into the markup, authors could share a single file that preserved layout and visual context without the need for additional software or plugins. This method was especially appealing to developers working on open-source or collaborative projects, where accessibility and transparency were priorities. The ability to view and modify the document in any basic text editor further reinforced the appeal of DHTML as a flexible, freely editable medium for sharing information.

The early web was defined by experimentation with file formats and delivery methods, as developers sought ways to balance functionality with broad compatibility. Embedding images within HTML was one of many creative solutions born from the constraints of limited bandwidth and inconsistent browser capabilities. While the practice never achieved widespread adoption for everyday web pages, it found a niche in specialized use cases such as documentation, offline archives, and prototypes. These efforts contributed to a deeper understanding of how data could be structured and transmitted, influencing later developments in web standards and application design.

Looking back, the persistence of such techniques reveals a recurring theme in web development: the drive to make information as self-sufficient as possible. Even as technology evolves, the core idea of bundling resources into a single file remains relevant for scenarios where network access is unreliable or simplicity is paramount. The lessons learned from early cross-browser embedding continue to inform modern approaches to offline web applications and progressive enhancement. This history underscores the importance of creative problem-solving in the face of technical limitations, a spirit that still animates the work of developers today.

One potential application for DHTML is as a lightweight, freely editable, self-contained document format. It can be used as a flow-based replacement for PDF. In fact, it is possible to create documents that are self-contained — including embedded images — without relying on external image files.

The Problem with Data URLs

At the time of writing, data URLs offered a standards-based way to embed images directly in HTML. Netscape, Mozilla, and Firefox supported them, but Internet Explorer did not. This meant any truly cross-browser self-contained document needed a different approach.

The Technique

The solution encodes raw image data as ASCII strings stored within the HTML file itself. These strings are unpacked dynamically at runtime using JavaScript. Rather than relying solely on compression, the method employs Run-Length Encoding (RLE) — chosen primarily for the table-cell savings it provides when the encoded data sits inside HTML table structures.

A grainy black-and-white film photograph of a close-up on a computer screen showing raw HTML source code with ASCII characters

Why DHTML Over PDF?

DHTML documents are inherently editable with any text editor, flow naturally in a browser window, and require no special viewer beyond a web browser. For technical documentation, reports, or portfolios, this makes DHTML a compelling alternative — especially when images must travel with the document as a single file.

Browser Compatibility

  • Netscape / Mozilla / Firefox — fully supported
  • Internet Explorer — supported via the encoding technique
  • No server-side processing required; everything runs client-side

A working demonstration is available at the Embedded Image Example page, where original images are shown alongside their embedded counterparts with unpacking-time measurements.

See It in Action

The companion demonstration page shows original and embedded images side by side, with real-time unpacking metrics.

Embedded Image Demo