Embedding Images in HTML Documents

A cross-browser technique for incorporating image data directly into self-contained HTML files — no external assets required.

Read the Article
A grainy analog film photograph of a dimly lit desk with a CRT monitor glowing in warm amber tones, loose printouts and cables scattered across the surface.
A close-up grainy film still of printed HTML code on textured paper, soft natural daylight, muted off-white and warm gray tones.

How the embedding works

This demonstration shows a method for storing image data as ASCII-encoded strings directly inside an HTML document. The images are unpacked dynamically at runtime — no separate image files are needed.

The technique uses Run-Length Encoding (RLE) not primarily for compression, but to reduce the number of table cells required to render the image. This makes the approach practical across browsers that lack native support for data URLs.

4
Browsers Supported
RLE
Encoding Method
ASCII
Storage Format

Cross-browser support

This method was developed to bridge a gap in browser capabilities. At the time of its creation, data URLs were unsupported in Internet Explorer and had limitations in Netscape, Mozilla, and Firefox. The technique works across all four:

  • Netscape — supported
  • Mozilla — supported
  • Firefox — supported
  • Internet Explorer — supported

The approach was originally developed around 2004 and refined over the following years. As Benn Herrera noted in March 2007, the technique was already going on three years old — and the lack of a simpler alternative remained notable.

This project explores how images can be embedded directly into HTML documents without relying on external files. By converting image data into ASCII-encoded strings and storing them inline, the technique creates fully self-contained web pages that work across different browsers. The method uses Run-Length Encoding not primarily for compression, but to reduce the number of data cells needed to reconstruct the visual content at runtime. This approach proves especially useful for sharing single-file demonstrations, portfolios, or archived documents where keeping all assets bundled together simplifies distribution and ensures the page renders reliably regardless of network conditions or file availability.

The technical foundation of this embedding method draws on long-standing practices in data representation and browser rendering. Rather than loading images through separate HTTP requests, the encoded strings are unpacked dynamically when the page loads. The cross-browser compatibility is achieved by relying on well-supported JavaScript functions and standard HTML table structures. While the technique prioritizes portability over storage efficiency, the RLE step helps keep the embedded data manageable. For developers working on small-scale projects, prototypes, or educational content, this approach offers a practical way to share interactive examples without worrying about missing assets or broken image paths.

This demonstration fits within a broader portfolio of experiments that bridge creative coding and practical web development. From early ActionScript prototypes to modern JavaScript implementations like JSTetris, the work reflects an ongoing interest in how code can generate, manipulate, and display visual content efficiently. The image embedding technique continues that thread by solving a specific real-world constraint: how to ship a complete browser-based experience in a single file. Whether used for archiving digital art, distributing offline-friendly tools, or simply learning how browsers handle inline data, this method opens up possibilities for more resilient and self-contained web publishing.

See it in action

The page at this URL renders a side-by-side comparison: standard <img> tags on the left, and the same images embedded and unpacked dynamically on the right. Each embedded image reports its unpack time, RLE size, and uncompressed dimensions.

Original Image

Standard <img> tag referencing an external file.

Embedded Image

ASCII-encoded data unpacked dynamically in the browser.

An accompanying article explains the full rationale, including why DHTML was proposed as a lightweight, freely editable alternative to PDF for self-contained documents.

Related resources

  • Full technical article — detailed explanation of the cross-browser embedding technique.
  • Home — return to Benn Herrera's portfolio and other projects.