Kevin Powell - CommunityKP-C
Kevin Powell - Community15mo ago
30 replies
snxxwyy

svg sizing when in img tag

Hey, so if i have an svg in a file, e.g.
// example.svg
<svg width="10px" height="10px" viewbox="...">
  <path></path>
</svg>

and i import it into my html with an img tag, if my img tag has display: block on it because of the img reset, meaning it should take up 100% of the container width, why is the size of the img tag when i take a look in dev tools equivalent to the width and height attribute values of the svg it's importing (in this case 10px)?

Is this because those attributes inherit over to the img tag and become it's width and height attributes? I always thought the img tag would be 100% of the container due to display: block; and the svg inside it would just be it's own size.

I'd appreciate if someone could help clear this up, thanks in advance.
Was this page helpful?