SVG to Data URI and Base64 Encoder

Turn an SVG icon into a compact data URI for CSS or HTML, recolour it, see which encoding is smaller, or decode an existing data URI.

브라우저에서 실행됩니다. 파일은 기기 밖으로 나가지 않습니다. 확인하는 방법 보기

…

사용 방법

  1. 1
    Add the SVG

    Open an SVG file or paste the markup.

  2. 2
    Set minify options

    Choose what to remove and the number precision.

  3. 3
    Recolour if needed

    Change colours or set them to currentColor.

  4. 4
    Check the preview

    Switch between checker, light and dark backgrounds.

  5. 5
    Compare sizes

    Read the byte and gzip sizes of each encoding.

  6. 6
    Copy a snippet

    Copy the CSS, mask, img or raw data URI, or decode one in the second tab.

이 도구 소개

Small SVG icons, dividers and background patterns are often cheaper to inline than to request as separate files. A data URI puts the whole file into a CSS url() or an img src, so the browser has it as soon as the stylesheet or page arrives. There are two ways to encode an SVG for this. Base64 works everywhere but makes the text about a third larger and hides it from gzip's pattern matching. URL-encoding keeps the markup readable and usually smaller, but only if the right characters are escaped: the percent sign, the hash, angle brackets, curly braces and double quotes, plus any non-ASCII text. Many generators escape far more than needed or forget the hash, which silently breaks colours such as #FF0000. This tool does the minimal, correct escaping, swaps double quotes for single quotes so the result fits inside url(""), and shows both encodings side by side with their sizes.

Minify first

Exported SVG files carry baggage: an XML declaration, editor comments, metadata blocks, Inkscape and Sketch attributes, and coordinates with six decimals. The minifier removes those safely with switches you control, rounds numbers in path data, points, viewBox and transforms to the precision you choose, collapses whitespace, and adds the xmlns attribute that browsers require when an SVG is used as an image. Keep title and desc for meaningful images; remove them only for decorative icons.

Recolour

The colour panel lists every fill, stroke and stop colour with how often it appears. Change one with the colour picker or type any CSS colour. The currentColor button is useful when the SVG will be inlined, and the CSS mask snippet lets a data URI icon take the text colour of its element, because a mask uses only the shape and fills it with background-color.

Snippets and sizes

You get a CSS background-image line, a mask block, an HTML img tag, the URL-encoded data URI and the Base64 data URI, each with a copy button. The statistics show the original, the minified SVG and both URIs in bytes, and their gzip sizes when your browser supports compression streams, which is what matters once the stylesheet is served compressed.

Decode

Paste a data URI, a whole CSS url() value or an img tag. The tool detects Base64 or URL-encoding, shows a preview and gives back clean SVG markup that you can download or send to the encoder for editing.

Limits

The minifier is a set of careful text rules, not a full optimiser like SVGO; it does not merge paths, convert shapes or remove hidden elements. Scripts inside an SVG do not run from an img or CSS background, and the tool warns if one is present. Very large or photographic SVGs belong in separate cacheable files rather than data URIs.

풀이 예시

An Inkscape export of a 24 by 24 check badge is 668 bytes. With default minify settings and two-decimal precision it shrinks to 307 bytes; coordinates such as 10.333333 become 10.33 and the metadata and editor attributes disappear. The URL-encoded data URI is 354 bytes and the Base64 version 438 bytes, so URL-encoding saves about 19 percent here. Setting the white stroke #FFFFFF to currentColor and using the mask snippet lets the same icon appear dark on a light card and white on a blue button.

한눈에 보기

자주 묻는 질문

Should I use Base64 or URL-encoding?

URL-encoding is usually smaller and compresses better inside gzipped CSS. Base64 is the safe choice for e-mail templates and tools that reject special characters.

Why are double quotes changed to single quotes?

The snippet sits inside url("..."), so double quotes in the SVG would end the string early. Single quotes are valid SVG and need no escaping.

Why does my colour disappear in a data URI?

An unescaped # starts a URL fragment, so everything after it is ignored. This tool always encodes # as %23.

Can a data URI icon change colour with CSS?

Not as a background image. Use the CSS mask snippet: the SVG supplies the shape and background-color supplies the colour, which can be currentColor.

Is the minifier safe for all SVGs?

Its rules only remove comments, metadata, editor data and whitespace and round numbers. Check the preview; if fine details shift, raise the precision.

Is my file uploaded?

No. Everything, including the gzip size test, runs in your browser.

완전 무료요금 없음, 가입 없음
파일은 비공개로 유지됩니다모든 작업이 브라우저 안에서 이루어집니다
내 언어로 쉽게여러 언어로 제공