Frontend & Web Standards

How to Convert Raw SVG Icons to Accessible React & TypeScript JSX Components

Fix React DOM property warnings (stroke-width vs strokeWidth, class vs className), replace hardcoded hex fills with currentColor, and make inline SVG icons keyboard-accessible.

By Cometflow Web Standards Desk • Updated 2026-10-19

Exporting an icon from Figma or Illustrator and pasting the raw <svg> markup directly into a React .tsx component triggers console warnings and styling headaches. Raw SVG files contain XML namespaces (xmlns:xlink), kebab-case attributes (stroke-width, fill-rule), and fixed pixel dimensions that resist responsive CSS scaling.

1. Before & After: Raw SVG vs. Clean React JSX

// ❌ RAW EXPORT FROM DESIGN TOOL:
<svg width="24px" height="24px" viewBox="0 0 24 24" class="icon" xmlns:xlink="http://www.w3.org/1999/xlink">
  <path d="M5 12h14M12 5l7 7-7 7" stroke="#111827" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

// ✅ OPTIMIZED ACCESSIBLE REACT COMPONENT:
export function ArrowRightIcon(props: React.SVGProps<SVGSVGElement>) {
  return (
    <svg
      viewBox="0 0 24 24"
      width="1em"
      height="1em"
      fill="none"
      aria-hidden="true"
      {...props}
    >
      <path
        d="M5 12h14M12 5l7 7-7 7"
        stroke="currentColor"
        strokeWidth={2}
        strokeLinecap="round"
        strokeLinejoin="round"
      />
    </svg>
  );
}

Automate this conversion in one click using the SVG to JSX Converter, and if you need to extract exact brand hex codes from a raster reference first, use the Color Picker from Image.

Frequently Asked Questions

How do I make an SVG icon inherit the Tailwind text color of its parent button?

Replace hardcoded hex values like fill="#000000" or stroke="#1e293b" with fill="currentColor" or stroke="currentColor". Then applying text-blue-600 on the parent button automatically colors the SVG.

Why does React log a warning about invalid DOM property stroke-width or clip-path?

JSX uses camelCase for standard SVG DOM properties: stroke-width must be strokeWidth, stroke-linecap becomes strokeLinecap, fill-rule becomes fillRule, and class becomes className.