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.
Altro dal blog
Cos'è Becoderr? Oltre 120 strumenti online gratuiti in un unico posto
Becoderr è una raccolta gratuita di oltre 145 strumenti online per PDF, immagini, JSON, testo, sviluppatori e attività quotidiane: privato, veloce e senza registrazione.
Come comprimere le immagini senza perdere qualità
Riduci le dimensioni delle immagini fino al 90% mantenendo le foto nitide. Guida rapida per comprimere JPG e PNG online, gratis e in privato.
Come convertire un PDF in un documento Word modificabile
Trasforma qualsiasi PDF in un .docx modificabile in Microsoft Word, gratis e senza registrazione.