import Image from 'next/image'
...
<Image src="/emotion.svg" alt="emtion" width={50} height={50} />
I want to change the SVG color in next/image.
But in CSS,
img {
fill="#ffffff"
}
is not working.
How can I solve this?
import Image from 'next/image'
...
<Image src="/emotion.svg" alt="emtion" width={50} height={50} />
I want to change the SVG color in next/image.
But in CSS,
img {
fill="#ffffff"
}
is not working.
How can I solve this?
I recommend you to not to use svg files directly, but use Playground SVG (https://react-svgr.com/playground/), convert the file to JS and then you can change the color and other stuff by props.
I am using Next/Image and inserting the SVG url dynamically. For this case I needed to use css filter to somehow change the SVG color.
I think the best solution here is not to use Image. by default the nextjs Image component is not doing any optimization on svg's. You will then have multiple options/solutions to your problem:
next.config.js file using @svgr/webpack:// next.config.js
webpack(config) {
config.module.rules.push({
test: /\.svg$/,
use: ["@svgr/webpack"]
});
return config;
}
// The file where u want to import the svg
import YourSvg from './public/yourSvg.svg'
// I recommend using the `currentColor` property on your svg, but you can also pass the color as prop
<YourSvg color="red" />
babel-plugin-inline-react-svg: https://github.com/vercel/next.js/discussions/20993#discussioncomment-760119
