Why is 1em shorter than the default font size?

Ghasan

I was doing some experiments, and then I ran into this issue. I sat a div's height to 1em, and I expected the div to contain the whole height of the text within, but it did not. 1em is my browser is 16px.

When I did not specify the div's height, it successfully contained the whole height of the text, and when inspected, it turned to be of height 19px.

Is my understanding of em wrong, as I thought it should represent the default font height of the browser.

div {
  margin: 0;
  padding: 0;
}
.first {
  height: 1em;
  background: green;
}
.second {
  background: orange;
}
<div class="first">سلامًا Say I Wantأًّ</div>
<br />
<div class="second">سلامًا Say I Wantأًّ</div>

https://jsfiddle.net/9t43kyu2/1/

peterh - Reinstate Monica

The typographical line-height of a text isn't surely the actual height of the rendered text in pixels:

enter image description here

The line-height css parameter of a text contains only the height between "caps height" and the "baseline". It is on most cases 1em on my experience and also on most non-standard sources of the net. But its standardized details are better described in @web-tiki 's answer.

If there are characters which have parts over it or below it, they will result a text whose height (in pixels) is bigger as the line height (in pixels).

The text can have small details which are below or over the standard text line. For example, the lowest part of an y, or the uppest parts of a non-ascii Ű character. These causes continously problems in the positioning.

If you don't set the div height, it will be by default auto, which mean, the whole content will be in it. If you specify the div height to the actual line size, without padding, border and margin, then some pixel of your text will maybe overflow. You only didn't see it, because the default value of the overflow css-parameter is visible.

Best test for that: create a div with the following settings:

#divId {
  height: 1em;
  line-height: 1em;
  overflow: hidden;
}

...and copy-paste an into its content (but characters are also okay). You will see it clipped on both sides.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Element with font-size less than 1em does not cover parent element

1em is smaller than browser default

Why is the div bigger than the font-size?

Why is lineHeight of UIFont larger than font size?

What doe the meaning of font-size:1em/2em?

Does it ever make sense to set the font-size to 1em?

why is 1 inch in computer screen shorter than 1 inch in real?

Flutter default font size

Table default font size

Why is bootstrap setting the default font-size to 10px?

Why is the default font size of UITextField loaded from Nib is too small?

Is the default font-size of every browser 16px? Why?

why some websites change default font size to 14px

OpenCV: Why is one trackbar shorter than others?

How to get element font-size inline style when there is more than 1 font-size css

Converting em to px in Javascript (and getting default font size)

Summernote set default font size and font

Default font and font size in LibreOffice Calc 4.2.3.3

Sticky footer when content is shorter than page size

ORA-24920 but text is shorter than column size

Calculating an em value -1px in CSS/SASS without assuming the user's default font size

Why is font-size: 16px bigger in Internet Explorer 11 than in FireFox?

Why does text with a larger font-size show up lower than other text and how to stop it?

Why isn't em doubling the defined font size?

Why does VS Code's default editor font size differ based on Operating System?

Why is the default font weight 400?

Why is the range of a mobile Wi-Fi hotspot shorter than that of a router?

Why is a input box of type="submit" shorter than its given height?

xlsxwriter - Why shorter strings occupy the same size as twice larger strings?