react-svg-inliner

react-svg-inliner

Inline SVG loader for React and Next.js, built with modern standards.

NPM
Interactive Demo

Click "Active" to toggle between outlined and filled versions. Change colors using CSS.

Installation

npm install react-svg-inliner

Usage

"use client";

import { SvgInline } from "react-svg-inliner";

<SvgInline src="/icons/logo.svg" className="w-6 h-6" />

Advanced Usage (Active State)

Declarative handling of active states for navigation.

<SvgInline
  src="/icons/home-outline.svg"      // Default icon
  activeSrc="/icons/home-filled.svg" // Active icon
  active={isActive}                  // Boolean to switch
  className="w-8 h-8 transition-colors"
  title="Go to Home"
  id="home-icon"
/>

Props

PropTypeDescription
srcstringRequired. Relative URL to the default SVG.
activeSrcstringURL to the "active" version of the SVG.
activebooleanIf true, the component renders activeSrc instead of src.
classNamestringCSS class string applied to the wrapper.
styleCSSPropertiesInline styles applied to the wrapper.
titlestringTitle attribute for accessibility (tooltip).
onError(err: Error) => voidCallback function if the SVG fails to load.
idstringID to assign to the SVG element. Overrides the ID in the file if present.