How do I adjust the size/color of an svg image in nextjs?
I want to adjust the color and size of an svg image "headset.svg".
Before I was using next/image:
<Image
src={'/headset.svg'}
alt='logo'
width={30}
height={30}
className='object-contain'
/>
This works well for the size but I want to change the color (in css) as well.
I've added the svgr tool to make a component of the svg image.
next.config.js:
module.exports = {
webpack(config) {
config.module.rules.push({
test: /\.svg$/i,
issuer: /\.[jt]sx?$/,
use: ['@svgr/webpack'],
})
return config
},
}
Code:
import Logo from '../public/headset.svg';
...
<Logo className='w-[50px] h-[50px] text-black' />
But the css (className='w-[50px] h-[50px] text-black') is not being applied to the svg image.
Posted Jul 21, 2023, 7:06 PM UTC
SVGs use fill and stroke for color. So you’d wanna do something like fill-red-100 or stroke-blue-400
So "<Logo className='fill-red-100' />" ? Doesn't seem to work either