ASCII to Data URI Converter

Validates that input is strict 7-bit ASCII, then Base64-encodes it and prefixes the result with data:text/plain;charset=us-ascii;base64,, producing a self-contained data URI honestly labeled with the us-ascii charset it actually contains. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-27

Overview

Introduction

A data URI embeds a whole payload directly inside a URL string, no separate file or request needed, which is handy for small, self-contained text values used in HTML, CSS, or JavaScript source.

This tool builds that URI specifically for strict ASCII text: validate it's within 0-127, Base64-encode it, and prefix the correct MIME type, charset, and encoding scheme.

What Is ASCII to Data URI Converter?

A converter that checks the input is strict 7-bit ASCII, then wraps its Base64 encoding in the data:text/plain;charset=us-ascii;base64, scheme.

The result is a single self-contained string that any tool understanding data URIs can decode back into the exact original ASCII text.

How ASCII to Data URI Converter Works

The input is validated character-by-character against the 0-127 ASCII range using this category's shared strict-ASCII validator.

If validation passes, the original string is Base64-encoded directly via btoa() (safe here since ASCII code points are already Latin1-safe byte values) and prefixed with data:text/plain;charset=us-ascii;base64,.

When To Use ASCII to Data URI Converter

Use it when you need to embed a small, verified-ASCII text payload directly in an HTML attribute, a CSS url(), or a JavaScript import without a separate network request.

It's a better fit than a generic data URI encoder whenever you specifically want the charset declaration to be accurate rather than guessed or omitted.

Features

Advantages

  • Produces an honestly-labeled data URI: the us-ascii charset parameter reflects a real validation step, not an assumption.
  • No UTF-8 conversion overhead, since validated ASCII input is already Latin1-safe for btoa().
  • Rejects non-ASCII input outright rather than mislabeling it as us-ascii.

Limitations

  • Base64 encoding adds roughly 33% overhead to the payload size, making this a poor fit for large text.
  • Only handles plain text; there's no JSON, HTML, or other structural validation beyond the ASCII character check.

Examples

Encoding a short phrase

Input

Hello

Output

data:text/plain;charset=us-ascii;base64,SGVsbG8=

The validated ASCII text is Base64-encoded and prefixed with the text/plain MIME type, us-ascii charset, and base64 encoding scheme.

Encoding text with punctuation

Input

Hi there!

Output

data:text/plain;charset=us-ascii;base64,SGkgdGhlcmUh

Spaces and punctuation are valid ASCII, so they encode the same way as letters.

Rejecting a non-ASCII character

Input

café

Output

Character "é" at position 4 has code point 233 (0xE9), which is outside the 7-bit ASCII range (0-127).

Encoding stops before any Base64 or URI wrapping happens, since the us-ascii charset would otherwise be a false label.

Best Practices & Notes

Best Practices

  • Reserve this for small, genuinely self-contained ASCII text; large payloads bloat the surrounding HTML/CSS/JS source.
  • Use Data URI to ASCII Converter to verify a round trip before relying on the URI elsewhere.

Developer Notes

Validation reuses the category's shared validateStrictAscii helper; encoding calls btoa(input) directly on the raw string with no TextEncoder step, since ASCII code points map one-to-one onto the Latin1 byte range btoa() expects, then prefixes the fixed data:text/plain;charset=us-ascii;base64, scheme string.

ASCII to Data URI Converter Use Cases

  • Embedding a short, verified-ASCII text snippet directly in an HTML data attribute or inline script
  • Referencing a small fixed ASCII payload from a CSS url() without a separate file
  • Producing a self-contained ASCII string for sharing or testing data URI handling

Common Mistakes

  • Using this for text that might contain non-ASCII characters and being surprised when it's rejected; use a general data URI encoder for arbitrary Unicode text instead.
  • Using this for large payloads, where the Base64 overhead and inline bloat outweigh the convenience of avoiding a request.

Tips

  • A rejection here is a fast way to confirm your text is (or isn't) pure ASCII before committing to embedding it.
  • Decode the result with Data URI to ASCII Converter to confirm the round trip matches your original input exactly.

References

Frequently Asked Questions