SVGs in Lovable can be used inline as JSX components or referenced via img tags. Inline SVGs give you full styling control with Tailwind classes but require valid JSX syntax (className instead of class, camelCase attributes). If your SVG appears blank, check that the viewBox attribute is set and that fill or stroke colors are not hardcoded to match the background. For SVG files in /public, reference them with root-relative paths in img src.
Why SVG graphics fail to render in Lovable projects
Lovable uses React with JSX, which means SVGs need to follow JSX rules rather than plain HTML rules. The most common rendering failure happens when you paste raw SVG code from a design tool like Figma or an icon website — the SVG uses HTML attributes (class, fill-rule, clip-path) that JSX does not accept. React requires camelCase equivalents: className, fillRule, clipPath. Another frequent issue is missing or incorrect viewBox values. The viewBox attribute defines the coordinate system of the SVG. Without it, the SVG may render at zero size or overflow its container. Design tools sometimes export SVGs without a viewBox, relying on explicit width and height instead, which breaks when you try to make the SVG responsive with Tailwind utility classes. Color problems are also common. SVGs exported from design tools often have hardcoded fill colors like fill="#000000" or fill="white". When your Lovable app uses a dark theme, a white-filled SVG disappears against a white background (or a black-filled SVG disappears on dark backgrounds). Using fill="currentColor" makes the SVG inherit the text color from its parent, adapting automatically to any theme.
- HTML attributes instead of JSX attributes: class instead of className, fill-rule instead of fillRule
- Missing viewBox attribute: SVG renders at zero dimensions or wrong aspect ratio
- Hardcoded fill colors that match the background, making the SVG invisible
- SVG file referenced via img src but the file path is wrong or not in /public
- SVGR transform not applied: importing an .svg file as a component without proper Vite configuration
Error messages you might see
Invalid DOM property `class`. Did you mean `className`?React does not accept the HTML class attribute in JSX. Change every class= to className= in your SVG code. This also applies to for= (use htmlFor=) and other HTML-specific attributes.
Invalid DOM property `fill-rule`. Did you mean `fillRule`?SVG attributes with hyphens must be converted to camelCase in JSX. Common ones: fill-rule becomes fillRule, clip-path becomes clipPath, stroke-width becomes strokeWidth, stroke-linecap becomes strokeLinecap.
Namespace tags are not supported by defaultSome SVGs include XML namespace prefixes like xlink:href. In React JSX, use xlinkHref (camelCase, no colon). Better yet, replace xlink:href with the standard href attribute since xlink is deprecated in modern SVG.
Before you start
- A Lovable project open in the editor
- Your SVG code or SVG file ready (exported from Figma, Illustrator, or downloaded from an icon library)
- Basic understanding of where to paste code in Lovable (use @filename references or Dev Mode)
How to fix it
Convert SVG HTML attributes to JSX-compatible camelCase
React's JSX parser rejects HTML-style attributes and will throw errors or silently break rendering
Convert SVG HTML attributes to JSX-compatible camelCase
React's JSX parser rejects HTML-style attributes and will throw errors or silently break rendering
When pasting SVG code into a Lovable React component, you must convert all hyphenated attributes to camelCase. The most common conversions are: class → className, fill-rule → fillRule, clip-rule → clipRule, clip-path → clipPath, stroke-width → strokeWidth, stroke-linecap → strokeLinecap, stroke-linejoin → strokeLinejoin, and xlink:href → href. You can also prompt Lovable to do this: 'Convert this SVG to valid React JSX' and paste the SVG code.
<svg class="icon" viewBox="0 0 24 24" fill="none"> <path d="M12 2L2 7l10 5 10-5-10-5z" fill-rule="evenodd" clip-rule="evenodd" stroke-width="2" stroke-linecap="round" /></svg><svg className="icon" viewBox="0 0 24 24" fill="none"> <path d="M12 2L2 7l10 5 10-5-10-5z" fillRule="evenodd" clipRule="evenodd" strokeWidth="2" strokeLinecap="round" /></svg>Expected result: No JSX attribute warnings in the console. The SVG renders correctly in the preview.
Add or fix the viewBox attribute for responsive sizing
Without viewBox, SVGs cannot scale responsively and may render at zero or incorrect dimensions
Add or fix the viewBox attribute for responsive sizing
Without viewBox, SVGs cannot scale responsively and may render at zero or incorrect dimensions
Check that your SVG has a viewBox attribute on the root svg element. The viewBox defines the coordinate space: viewBox="0 0 24 24" means the content fits in a 24x24 unit box. If your SVG has width and height but no viewBox, add one based on those dimensions. Then remove the fixed width/height and use Tailwind classes (w-6 h-6, w-12 h-12, etc.) to control the displayed size. This makes the SVG responsive.
<!-- SVG without viewBox — won't scale properly --><svg width="200" height="200" xmlns="http://www.w3.org/2000/svg"> <circle cx="100" cy="100" r="80" fill="blue" /></svg><!-- SVG with viewBox — scales to any size via Tailwind --><svg viewBox="0 0 200 200" className="w-12 h-12" xmlns="http://www.w3.org/2000/svg"> <circle cx="100" cy="100" r="80" fill="blue" /></svg>Expected result: The SVG scales proportionally to the size specified by Tailwind classes. It adapts correctly on different screen sizes.
Use currentColor for theme-aware SVG colors
Hardcoded fill colors make SVGs invisible on matching backgrounds and break when themes change
Use currentColor for theme-aware SVG colors
Hardcoded fill colors make SVGs invisible on matching backgrounds and break when themes change
Replace hardcoded color values like fill="#000000" or fill="white" with fill="currentColor". This makes the SVG inherit the text color of its parent element, so it automatically adapts to light and dark themes. For Tailwind styling, you can then control the SVG color using text color utilities on the parent: text-primary, text-muted-foreground, text-red-500, etc.
<svg viewBox="0 0 24 24" className="w-6 h-6"> <path d="M12 2L2 7l10 5 10-5-10-5z" fill="#000000" /> {/* Invisible on dark backgrounds */}</svg><svg viewBox="0 0 24 24" className="w-6 h-6"> <path d="M12 2L2 7l10 5 10-5-10-5z" fill="currentColor" /> {/* Inherits color from parent — works on any background */}</svg>Expected result: The SVG color matches the surrounding text color and adapts automatically when the user switches between light and dark themes.
Reference SVG files from the /public folder using img tags
For complex SVGs that you do not need to style with CSS, img tags are simpler and avoid JSX conversion
Reference SVG files from the /public folder using img tags
For complex SVGs that you do not need to style with CSS, img tags are simpler and avoid JSX conversion
If you have an SVG file (like a logo or illustration) that does not need dynamic styling, place it in the /public folder and reference it with an img tag. Upload the .svg file to /public via GitHub or Dev Mode, then use a root-relative path in the src attribute. This avoids JSX attribute conversion entirely. The tradeoff is that you cannot style individual SVG elements with Tailwind — the img tag treats the SVG as a flat image.
<!-- Broken: wrong path, SVG not in /public --><img src="logo.svg" alt="Logo" />{/* 404: file not found */}<!-- Working: SVG file is in /public/images/logo.svg --><img src="/images/logo.svg" alt="Logo" className="w-32 h-auto" />{/* Root-relative path — Vite serves /public at / */}Expected result: The SVG image loads without 404 errors. The img tag displays the SVG at the size specified by Tailwind classes.
Complete code example
1import { cn } from "@/lib/utils";23interface SvgIconProps {4 className?: string;5}67// Reusable inline SVG component with proper JSX attributes8// Uses currentColor so it inherits the parent's text color9const SvgIcon = ({ className }: SvgIconProps) => {10 return (11 <svg12 viewBox="0 0 24 24"13 fill="none"14 xmlns="http://www.w3.org/2000/svg"15 className={cn("w-6 h-6", className)}16 >17 {/* Star icon — fillRule and strokeLinejoin in camelCase */}18 <path19 d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"20 fill="currentColor"21 fillRule="evenodd"22 clipRule="evenodd"23 />24 </svg>25 );26};2728// Example usage in a page component29const IconDemo = () => {30 return (31 <div className="flex items-center gap-4 p-6">32 {/* Default size and color from parent */}33 <span className="text-primary">34 <SvgIcon />35 </span>3637 {/* Custom size via className override */}38 <span className="text-yellow-500">39 <SvgIcon className="w-10 h-10" />40 </span>4142 {/* SVG from /public as img (no inline styling control) */}43 <img44 src="/images/logo.svg"45 alt="Company logo"46 className="w-8 h-8"47 />48 </div>49 );50};5152export { SvgIcon };53export default IconDemo;Best practices to prevent this
- Always include a viewBox attribute on SVG elements — it enables responsive scaling with Tailwind width/height classes
- Use fill="currentColor" and stroke="currentColor" so SVGs adapt to light and dark themes automatically
- Convert all hyphenated SVG attributes to camelCase for JSX: fill-rule → fillRule, stroke-width → strokeWidth, clip-path → clipPath
- For simple icons, use inline SVG components for full Tailwind styling control; for complex illustrations, use img tags with SVG files in /public
- Remove unnecessary metadata and comments from exported SVGs to reduce file size — tools like SVGOMG can optimize SVGs before you paste them
- Use the cn() utility from shadcn/ui to merge default and custom classNames on SVG wrapper components
- Test SVGs in both light and dark mode to catch invisible-on-background color issues early
Still stuck?
Copy one of these prompts to get a personalized, step-by-step explanation.
I have an SVG from Figma that I need to use in my Lovable (lovable.dev) React + TypeScript project. The SVG is not rendering correctly. Here is the raw SVG code: [paste your SVG code here] Please: 1. Convert all HTML attributes to valid React JSX (camelCase) 2. Add a viewBox if missing and remove fixed width/height 3. Replace hardcoded fill colors with currentColor where appropriate 4. Wrap it in a reusable React component with a className prop for Tailwind sizing
I pasted an SVG icon into @src/components/icons/MyIcon.tsx but it is not rendering. The SVG has HTML attributes that need to be converted to JSX camelCase format. Please fix all SVG attributes (class → className, fill-rule → fillRule, clip-path → clipPath, stroke-width → strokeWidth), add a viewBox if missing, and replace hardcoded fill colors with currentColor so the icon works with both light and dark themes.
Frequently asked questions
Should I use inline SVG or img tags for SVGs in Lovable?
Use inline SVG when you need to style individual elements with Tailwind (change colors, hover effects, animations). Use img tags when the SVG is a complex illustration or logo that does not need dynamic styling. Inline SVGs are more flexible but require JSX attribute conversion.
Why is my SVG invisible in Lovable even though the code looks correct?
The most common cause is a hardcoded fill color that matches the background. An SVG with fill="white" disappears on a white background. Replace hardcoded colors with fill="currentColor" to inherit the parent element's text color, which adapts to any theme.
How do I make an SVG responsive in Lovable?
Add a viewBox attribute to the svg element (like viewBox="0 0 24 24"), remove any fixed width and height attributes, and use Tailwind classes like w-8 h-8 or w-full to control the displayed size. The viewBox ensures the SVG scales proportionally.
What SVG attributes need to change for React JSX?
All hyphenated attributes must become camelCase: class → className, fill-rule → fillRule, clip-rule → clipRule, clip-path → clipPath, stroke-width → strokeWidth, stroke-linecap → strokeLinecap, stroke-linejoin → strokeLinejoin. Also change xlink:href to just href.
Can I import SVG files as React components in Lovable?
Lovable's default Vite configuration does not include SVGR (the plugin that transforms .svg imports into components). You can ask Lovable to add the vite-plugin-svgr package, or simply paste the SVG code directly as inline JSX in your component, which is the more reliable approach.
How do I style SVGs with Tailwind in Lovable?
For inline SVGs, apply Tailwind classes directly to the svg element: className="w-8 h-8 text-primary". Use text color utilities to change the SVG color when fill or stroke is set to currentColor. For SVGs loaded via img tags, you can only control size and spacing, not internal colors.
What if I can't get my SVG rendering correctly?
If your SVG has complex gradients, masks, or filters that break during JSX conversion, RapidDev's engineers can help. They have handled SVG integration issues across 600+ Lovable projects and know which SVG features work reliably in React and which need workarounds.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your issue.
Book a free consultation