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.
블로그의 다른 글
Becoderr란? 145개 이상의 무료 온라인 도구를 한곳에
Becoderr는 PDF, 이미지, JSON, 텍스트, 개발자용, 일상 작업을 위한 145개 이상의 무료 온라인 도구 모음입니다. 비공개, 빠름, 가입 불필요.
화질 저하 없이 이미지 압축하는 방법
사진을 선명하게 유지하면서 이미지 용량을 최대 90%까지 줄이세요. JPG와 PNG를 무료로 안전하게 온라인 압축하는 간단 가이드.
PDF를 편집 가능한 Word 문서로 변환하는 방법
어떤 PDF든 Microsoft Word에서 편집할 수 있는 .docx로 변환하세요. 무료, 가입 불필요.