Changing size of the svg doesn't change the size of the content
See original GitHub issue🐛 Bug Report
I have created svg components successfully, but changing width or height doesn’t change icon size at all.
To Reproduce
Example created icon:
import * as React from 'react';
function SvgBurger(props: React.SVGProps<SVGSVGElement>) {
return (
<svg width={24} height={24} fill="none" xmlns="http://www.w3.org/2000/svg" {...props}>
<path
d="M18.54 12.258A6.547 6.547 0 0012 5.718a6.547 6.547 0 00-6.54 6.54c.001.043.008.086.02.128v3.348a2.55 2.55 0 002.548 2.548h7.944a2.551 2.551 0 002.548-2.548v-3.348a.47.47 0 00.02-.128zM6.427 15.052v-1.08c.184.048.36.12.525.216.314.165.704.37 1.422.37.717 0 1.108-.205 1.422-.37.277-.146.497-.261.981-.261s.704.115.982.261c.313.165.704.37 1.422.37s1.108-.205 1.422-.37c.278-.146.498-.261.982-.261s.704.115.981.261c.247.13.543.282 1.005.343v.52H6.428zm10.58-1.702c-.314-.165-.704-.37-1.422-.37s-1.109.205-1.423.37c-.277.146-.497.261-.981.261s-.704-.115-.982-.261c-.314-.165-.704-.37-1.422-.37s-1.108.205-1.422.37c-.278.146-.498.261-.982.261-.483 0-.703-.115-.98-.261-.24-.126-.526-.275-.966-.338v-.28h11.144v.84a1.996 1.996 0 01-.564-.222zM12 6.666a5.6 5.6 0 015.572 5.118H6.428A5.6 5.6 0 0112 6.666zm3.972 10.668H8.028A1.602 1.602 0 016.452 16h11.097a1.602 1.602 0 01-1.577 1.335z"
fill="#000"
/>
<path
d="M9.03 9.25l-.831.453.32.585.83-.453-.318-.586zM12.54 9.763l-.152.65.921.216.153-.649-.922-.217zM10.838 7.688l-.153.649.921.217.153-.65-.921-.216zM15.092 8.45l-.497.444.631.706.497-.444-.631-.706z"
fill="#000"
/>
</svg>
);
}
export default SvgBurger;
Expected behavior
I have worked with SVG React components, but normally it’s supposed to change size where it doesn’t now.
Link to repl or repo (highly encouraged)
https://codesandbox.io/s/friendly-andras-yxtev?file=/src/App.tsx
Run npx envinfo --system --binaries --npmPackages @svgr/core,@svgr/cli,@svgr/webpack,@svgr/rollup --markdown --clipboard
Paste the results here:
## System:
- OS: macOS 11.0
- CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
- Memory: 103.36 MB / 16.00 GB
- Shell: 5.8 - /bin/zsh
## Binaries:
- Node: 12.18.1 - /usr/local/bin/node
- Yarn: 1.22.4 - /usr/local/bin/yarn
- npm: 6.14.5 - /usr/local/bin/npm
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Why don't SVG images scale using the CSS “width” property?
You have to modify the viewBox property to change the height and the width correctly with a svg. It is in the <svg>...
Read more >How to Scale SVG | CSS-Tricks
Any height or width you set for the SVG with CSS will override the height and width attributes on the <svg> . So...
Read more >How to resize a SVG image - Medium
1. Change width and height in XML format ... Open the SVG file with your text editor. It should show lines of code...
Read more >Scaling of SVG backgrounds - CSS: Cascading Style Sheets
No width or height with intrinsic ratio. This image doesn't specify either a width or a height; instead, it specifies an intrinsic ratio...
Read more >How to Resize SVG in HTML - W3docs
In this tutorial, we want to demonstrate how you can resize SVG image in HTML. For that, you can change the values of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
few days back i got the same issue with webpack and rollup. in weback config file i added this rule
and there was already file-loader preconfigured which was handling the svg file. so i removed the svg from the file loader test. then it started working. make sure no other loader is handling svg in your webpack config.
@hacknlove your problem was the
viewbox
should beviewBox
, the plugin specifically looks for that, and my Inkscape appears to correctly saveviewBox
as well, did you by any chance manually add that?