How to Use an SVG in React, CSS or HTML
Convert SVG code into a React component, a data URI, a CSS background or an img tag, and learn the limits of each.
Four ways to use an SVG
You can drop the SVG into React as a component, embed it as a data URI, use it as a CSS background, or reference it from an img tag. The SVG to Code tool generates all four from the same pasted code, with a live preview.
React component
The tool converts attribute names for React, such as stroke-width to strokeWidth and class to className, and spreads props onto the svg element so you can set size and color. Inline style strings and xlink:href attributes are not converted, so change those by hand.
Data URI, CSS and img
The data URI, CSS background-image rule and img tag all embed the SVG without a separate file. An SVG used this way works as an image, so it cannot inherit currentColor from the surrounding text the way an inline SVG in React can.
Use trusted SVGs
The preview is shown as an image, so scripts inside a pasted SVG do not run on the page. Still, only use SVG from sources you trust in your own projects. Because the preview is an image, currentColor appears black there, while the generated React code inherits the color of the surrounding text.
Mehr aus dem Blog
Was ist Becoderr? Über 120 kostenlose Online-Tools an einem Ort
Becoderr ist eine kostenlose Sammlung von 145 Online-Tools für PDFs, Bilder, JSON, Text, Entwickler und Alltag — privat, schnell und ohne Anmeldung.
Bilder komprimieren ohne Qualitätsverlust
Reduziere die Bildgröße um bis zu 90 %, ohne dass Fotos unscharf werden. Kurze Anleitung zum Komprimieren von JPG und PNG online, kostenlos und privat.
PDF in ein bearbeitbares Word-Dokument umwandeln
Wandle jedes PDF in ein bearbeitbares .docx um, das du in Microsoft Word ändern kannst, kostenlos und ohne Anmeldung.