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.
Plus du blog
Qu'est-ce que Becoderr ? Plus de 120 outils en ligne gratuits au même endroit
Becoderr est une collection gratuite de plus de 145 outils en ligne pour PDF, images, JSON, texte, développeurs et tâches du quotidien : privé, rapide et sans inscription.
Comment compresser des images sans perdre en qualité
Réduisez la taille de vos images jusqu'à 90 % tout en gardant des photos nettes. Guide rapide pour compresser JPG et PNG en ligne, gratuitement et en privé.
Comment convertir un PDF en document Word modifiable
Transformez n'importe quel PDF en .docx modifiable dans Microsoft Word, gratuitement et sans inscription.