Cette page n’est pas encore traduite en français : elle s’affiche en anglais.

SVG to CSS Data URI Converter

Paste an SVG and get a compact, URL-encoded data URI plus ready-made background-image and recolorable mask-image CSS.

Mis à jour le
Encoding
Open .svg
CSS output
Data URI
background-image
mask-image (recolorable icon)

background-image preview

mask-image preview

Vos données ne quittent jamais votre ordinateur. Tout le traitement se fait localement dans votre navigateur.

Comment utiliser : SVG to CSS Converter

  1. Paste your SVG code, open an .svg file or load the sample.
  2. Keep Clean up SVG on to strip comments, metadata and editor attributes, and choose URL-encoded or Base64.
  3. Check both previews — the normal background image and the single-color mask version.
  4. Copy the data URI or the complete CSS rule and paste it into your stylesheet.

What is an SVG data URI?

A data URI embeds a file directly in your CSS instead of linking to it: background-image: url("data:image/svg+xml,…"). For small icons, dividers, patterns and custom checkboxes this saves an HTTP request, avoids a flash of missing images and keeps the asset next to the styles that use it.

URL-encoding vs Base64

SVG is text, so it doesn’t need Base64. Base64 inflates any file by about 33% and turns it into an unreadable blob that compresses poorly with gzip or Brotli. A URL-encoded SVG stays close to its original size and readable. Only a few characters must be escaped:

CharacterEncodedWhy
#%23Otherwise starts a URL fragment — colors like #fff break the image.
%%25The escape character itself.
< >%3C %3ERecommended for compatibility with strict parsers.
"' or %22Attribute quotes are switched to single quotes so the CSS can wrap the URI in double quotes.

Use Base64 only when a tool or framework rejects anything else. The size cards under the preview show both results so you can compare.

Recolorable icons with mask-image

An SVG used as a background image is rendered in isolation: CSS on the page can’t change its fills, and currentColor inside it won’t follow your text color. The mask-image snippet solves this by using the SVG only as a stencil and painting it with background-color: currentColor, so one icon works in any color, hover state or dark mode. The -webkit-mask line is still needed for some browsers.

Cleanup and limits

Cleanup removes the XML declaration, comments, <metadata>, <title> (meaningless in a background), Inkscape/Sodipodi/Sketch attributes and extra whitespace, and adds the required xmlns if it’s missing — without it the browser won’t render the image. Embed only small SVGs (a few KB): large data URIs bloat every CSS download and can’t be cached separately. For complex graphics, link the file instead. Need a React component rather than CSS? Use SVG to JSX; for raster images, see Image to Base64.

Using it in Webflow

Webflow’s Backgrounds panel expects an uploaded image, so paste the generated rule into a <style> tag in an Embed element or in the page/site custom code, and give your element the matching class (e.g. icon).

Aussi recherché comme : svg to css, svg data uri, svg to data url, url encode svg, svg background image, svg to base64, mask-image, inline svg css.

Outils complémentaires : SVG to CSS Converter

  • URL Encode / Decode — Percent-encode text for safe use in URLs, decode encoded strings back to readable text, and break any URL down into its parts and query parameters.
  • Encodage / Décodage Base64 — Convertissez du texte au format Base64 et inversement, avec une prise en charge complète de l'UTF-8 (accents, emojis) ; passez au format Base64 compatible URL, ou glissez-déposez un fichier pour obtenir sa chaîne Base64 ou son URI de données.
  • CSS Minifier — Paste a stylesheet to shrink it instantly.
  • CSS Animation Generator — Design CSS animations on a real keyframe timeline.

Questions fréquentes

Why isn’t my SVG data URI showing up?
The usual causes are an unescaped # (in colors like #fff), a missing xmlns="http://www.w3.org/2000/svg" attribute, or unbalanced quotes between the CSS url("…") and the SVG attributes. This tool fixes all three.
Is URL-encoding or Base64 better for SVG in CSS?
URL-encoding is usually better: the result is smaller, readable and compresses well. Base64 adds about a third to the size and is only worth it when a toolchain requires it.
Can I change the color of an SVG background image with CSS?
Not directly — CSS can’t reach inside a background image. Either edit the fill in the SVG before encoding, or use the mask-image snippet and set background-color, which you can change on hover or in dark mode.
Do I need to include charset=utf-8 in the data URI?
No. Non-ASCII characters are percent-encoded as UTF-8, which browsers decode correctly for SVG, so data:image/svg+xml, is enough.
Is there a size limit for data URIs in CSS?
Browsers handle very large data URIs, but they bloat your stylesheet and can’t be cached separately. Keep embedded SVGs to a few kilobytes and link larger files.
Puis-je installer SVG to CSS Converter en tant qu’application web et l’utiliser hors ligne ?
Oui. SVG to CSS Converter est une application web installable (PWA) : elle s’installe depuis votre navigateur, sans passer par une boutique d’applications. Cliquez sur « Installer l’application » en haut de cette page dans Chrome ou Edge (Windows, macOS, Linux, ChromeOS) ; sur Android, utilisez « Partager » → « Ajouter à l’écran d’accueil » sur iPhone et iPad ; ou « Fichier » → « Ajouter au Dock » dans Safari 17+ sur Mac. L’application s’ouvre alors dans sa propre fenêtre avec sa propre icône, et comme elle s’exécute entièrement dans votre navigateur, elle continue de fonctionner hors ligne. Firefox sur ordinateur de bureau ne permet pas d’installer d’applications web. Comment fonctionne l’installation.

Outils similaires