Bought Pro? It is on your account. Sign in
SVG Creator Go Pro

How to use SVG icons in React

By · Updated · 3 min read

Short answerThe most flexible way is to turn each SVG into a small React component that takes size and color props and uses currentColor. Import SVG files with SVGR if you have many, use <img> for icons you never restyle, and mark decorative icons aria-hidden.

Quick steps

  1. Get a clean SVGDownload an SVG icon or copy its code. Make sure it has a viewBox (for example 0 0 24 24) and uses currentColor for fill or stroke.
  2. Convert it to JSXRename attributes to camelCase (stroke-width becomes strokeWidth, class becomes className) or use the React / JSX export in SVG Creator, which does it for you.
  3. Add size and color propsSet width and height from a size prop and leave the colour as currentColor so the icon follows the text colour.
  4. Use it with an accessible labelRender <BellIcon aria-hidden="true" /> next to visible text, or give icon-only buttons an aria-label.

Option 1: an inline icon component (recommended)

An inline component gives you full control: you can change size, colour and stroke with props and CSS, and there is no extra network request. This is the exact component SVG Creator's React / JSX export produces for its bell icon:

export default function BellIcon({ size = 24, color = "currentColor", ...props }) {
  return (
    <svg
      xmlns="http://www.w3.org/2000/svg"
      width={size}
      height={size}
      viewBox="0 0 24 24"
      fill="none"
      stroke={color}
      strokeWidth={2}
      strokeLinecap="round"
      strokeLinejoin="round"
      {...props}
    >
      <path d="M6 16v-5a6 6 0 0 1 12 0v5l2 2H4z" />
      <path d="M10 20.5a2 2 0 0 0 4 0" />
    </svg>
  );
}

Use it like any component. Because the colour defaults to currentColor, it inherits the text colour of its parent:

import BellIcon from './BellIcon';

export function NotificationsButton({ count }) {
  return (
    <button type="button" className="text-slate-700 hover:text-indigo-600" aria-label={`Notifications (${count} unread)`}>
      <BellIcon size={20} aria-hidden="true" />
    </button>
  );
}

Two JSX details trip people up when they paste raw SVG: attributes with hyphens must be camelCased (stroke-linecap → strokeLinecap), and class becomes className. Inline style strings must become objects.

Option 2: import .svg files as components with SVGR

If you keep icons as files, SVGR turns each import into a component at build time. The setup depends on your bundler:

SVGR keeps your SVG files as the source of truth, which is handy for designers who update icons in Figma. Make sure the files use currentColor; a hard-coded stroke="#000" cannot be recoloured with CSS.

Option 3: a plain <img> tag

For icons you never recolour (a logo, a decorative illustration) an image tag is the simplest option and the browser caches the file:

<img src="/icons/bell.svg" width="24" height="24" alt="" />

The catch: CSS cannot reach inside an <img>, so color, fill and hover states do nothing, and currentColor renders as black. Always set width and height to avoid layout shift, and use an empty alt="" when the icon is decorative.

Option 4: an SVG sprite with <use>

Large apps sometimes ship one sprite file with many <symbol> elements and reference them with <use href="/sprite.svg#bell" />. This shares one cached file across pages and still allows currentColor. It needs a build step to generate the sprite, and the sprite must be served from the same origin.

Which one should you pick?

MethodRecolour with CSSExtra requestBest for
Inline componentYesNoMost app icons
SVGR importYesNo (bundled)Large icon sets kept as files
<img> tagNoYes (cached)Logos, decorative art
Sprite + <use>YesOne, sharedHundreds of icons

Accessibility in React

Icons next to visible text are decorative: add aria-hidden="true" so screen readers skip them. Icon-only buttons need a name on the button, such as aria-label="Search". If the icon itself carries meaning (a status icon with no text), give the <svg> role="img" and an aria-label. More in accessible SVG icons.

Frequently asked questions

Should I use an icon library or my own SVG components?

Libraries such as Lucide or Heroicons are great when their icons cover your needs. When you need an icon they do not have, generate or draw it on the same 24×24 grid with the same stroke, export it as a component and keep it next to the library icons.

How do I change the size of an SVG icon in React?

Pass a size prop and set it as width and height on the <svg>. Keep the viewBox unchanged; it is what lets the icon scale without losing quality.

Why is my SVG icon black in React?

The SVG probably has fill="currentColor" or no fill at all and is rendered through an <img> tag, or its parent has no colour set. Render it inline and set color on a parent element.

Related guides

Free icons to try it with

Make an icon for your project

Type a few words, pick a style, export SVG, PNG, React or CSS.
Try SVG Creator free