Skip to content

CSS to Base64

Encode CSS as Base64 or as a data:text/css;base64 URI that can be loaded without hosting a separate stylesheet file.

Runs in your browser Free, no sign-up
Loading tool workspace...

What is CSS to Base64?

This CSS to Base64 converter encodes stylesheet code as Base64. With the Data URI Header option on, the output is a complete data URI, data:text/css;base64,…, that can be used anywhere a stylesheet URL is expected, for example <link rel="stylesheet" href="data:text/css;base64,…">, without hosting a separate .css file.

Turn the header off to get the raw Base64 string, which is useful when another system adds its own prefix or expects a Base64-encoded field. Text is encoded as UTF-8, so content such as icons in content: properties and non-English comments is preserved.

How to use CSS to Base64

  1. Paste your CSS into the input panel.
  2. Keep Data URI Header on for a complete data:text/css;base64 URI, or turn it off for raw Base
  3. Copy the output.
  4. Use it as the href of a link tag, in an @import, or wherever a Base64 stylesheet is required.

Key features

  • Encodes CSS to Base64 with UTF-8 support
  • Optional data:text/css;base64 header
  • Instant output as you paste
  • Copy or download the result
  • Runs entirely in your browser

Common use cases

  • Loading a stylesheet from a data URI where only a URL is accepted
  • Embedding styles in single-file HTML demos and bookmarklets
  • Passing CSS through JSON or configuration fields that expect Base64
  • Creating user styles and browser-extension styles
  • Testing Content Security Policy rules for data: URIs

Technical details & standards

The CSS is converted to UTF-8 bytes and encoded with standard Base64 (RFC 4648), producing output about 33% larger than the source. With the header enabled, the MIME type text/css is added so browsers treat the data URI as a stylesheet.

In most cases, inlining CSS in a <style> element is simpler and smaller than a Base64 data URI, because no encoding overhead is added. Data URIs are mainly useful when a URL is required, such as in some embedding systems, browser extensions or user-style tools. Note that a Content Security Policy must allow data: in style-src for data URI stylesheets to load.

Frequently asked questions

How do I use Base64 CSS in HTML?

Use the data URI as a stylesheet link: <link rel="stylesheet" href="data:text/css;base64,…">. It can also be used in @import url("data:text/css;base64,…").

Is a Base64 stylesheet faster than a normal CSS file?

Usually not. It saves an HTTP request but adds 33% to the size and cannot be cached separately. Inline <style> blocks or a normal cached stylesheet are typically better.

Why doesn't my data URI stylesheet load?

A Content Security Policy may block it: style-src must include data:. Also check that the URI starts with data:text/css;base64, so the browser recognizes it as CSS.

How do I embed an image in CSS as Base64?

Use the Image to Base64 Converter to create a data URI and put it in url(): background-image: url("data:image/png;base64,…");.

Is my data safe?

Processing happens locally in your browser. Tool input is not sent to CodeUnpack servers.

Does it work offline?

Once the page has loaded, this tool can process input without an internet connection.

More encoders & decoders tools

View all