Programming
EN
1 min read
Why there is a small space at the bottom of an img tag?
Is it tricky to remove?
I think this is a small tip but would help you out when developing websites. I just faced it recently and it took me a while to figure out the issue. So, I hope this will save you some time next time when you see it.

1920 x 1080, 69.7 KB, PNG
In case you haven't noticed, the space appears at the bottom of the image tag. If your image has the size of 200x200, then you, in some cases, may see that the actual frame that covers the image has the size of 200x2XX - which XX is bigger than 0. And this number depends on several factors, it maybe the font size, font family, lineheight.
Why?Why?
Why?Why?
The
img tag, by default, as the inline display mode, so the browsers treat them as for texts, and the space you see is actually for descenders.
Wikipedia
440 x 119, 10.3 KB, PNG
How to fix?How to fix?
How to fix?How to fix?
There are several ways
1. display: block;1. display: block;
1. display: block;1. display: block;
Yes, the simplest way is to change the display mode of the image to
block.2. vertical-align: bottom | top;2. vertical-align: bottom | top;
2. vertical-align: bottom | top;2. vertical-align: bottom | top;
3. line-height: 0;3. line-height: 0;
3. line-height: 0;3. line-height: 0;
This applies to the parent text element, for example,
html
<p style="line-height: 0;"> <img /> </p>
Hope this helps!
