What is height in em?
Asked Answered
W

7

21

I am still not clear what does size in em mean?
I have worked px, pt in CSS.
What would 0.8, 1.0 and 1.2 em mean?
I have seen height's in CSS like: height: 0.8em; or height: 1.2em;
How is it calculated?

Weisbrodt answered 9/8, 2010 at 7:13 Comment(2)
In addition ems, you can measure distances in ens and exs.Obie
A "em vs px" question: https://mcmap.net/q/53609/-why-em-instead-of-pxEwart
K
32

The meaning of "em" has changed over the years. Not all fonts have the letter "M" in them (for example, Chinese), but all fonts have a height. The term has therefore come to mean the height of the font – not the width of the letter "M."

Let's look at a simple example where we use the em unit to set font sizes:

<html>
  <style>
    h1 { font-size: 2em }
  </style>
  <body>
    <h1>Movies</h1>
  </body>
</html>

When used to specify font sizes, the em unit refers to the font size of the parent element. So, in the previous example, the font size of the h1 element is set to be twice the font size of the body element. To find what the font size of the h1 element will be, we need to know the font size of body. Because this isn't specified in the style sheet, the browser must find it from somewhere else – a good place to look is in the user's preferences. So, if the user sets the normal font size to 10 points, the size of the h1 element is 20 points. This makes document headlines stand out relative to the surrounding text. Therefore: Always use ems to set font sizes!

More Info

Kimberleykimberli answered 9/8, 2010 at 7:22 Comment(0)
I
22

1em is equal to the current font size.

2em means 2 times the size of the current font.

E.g., if an element is displayed with a font of 12 pt, then '2em' is 24 pt. The 'em' is a very useful unit in CSS, since it can adapt automatically to the font that the reader uses

Here's a link to other CSS units:

http://www.w3schools.com/cssref/css_units.asp

Inglis answered 9/8, 2010 at 7:16 Comment(0)
T
3

1em is equal to the current font size. 2em means 2 times the size of the current font. E.g., if an element is displayed with a font of 12 pt, then '2em' is 24 pt. The 'em' is a very useful unit in CSS, since it can adapt automatically to the font that the reader uses.

more here

Theone answered 9/8, 2010 at 7:18 Comment(0)
C
3

Paul is correct, however its "M" not "m". However this is an esoteric definition derived from typesetting/printing and isnt of much use in this case. In terms of whats going to be useful to you you its a percentage of font size.

Cist answered 9/8, 2010 at 7:19 Comment(1)
Well i was getting ready to clarify with neraly exactly ehat it says in the Wiki article you linked to so :-PCist
O
2

An em is the width of the letter "m" (in your current font and size).

Obie answered 9/8, 2010 at 7:13 Comment(2)
This is not actually so, it's an urban myth :-) Some fonts don't even have an "m" and even those that do have the width of their 'm's sometimes less than an em: en.wikipedia.org/wiki/Em_%28typography%29Gropius
It's not an urban myth, it's just a deprecated use of the term. adobe.com/uk/type/topics/glossary.html#ememspaceemquadUnderprivileged
A
2

Em is the size of a character. It will vary depending upon the font size. If the font size is 24 then 2Em will be equal to the space it should take to hold two characters of the font size 24.

As quoted from wiki.

An em is a unit of measurement in the field of typography. This unit defines the proportion of the letter width and height with respect to the point size of the current font.

FYI: En is half of Em. 0.5Em

Accumulate answered 9/8, 2010 at 7:20 Comment(0)
A
0

An em means "ephemeral unit" it is relative to the current font size of its parent element. For instance, the text in an <h1> heading is 2em by default. This comes from the fact that an <h1> inherits its text size from its parent element, the <body> of the document. If I set my <body> font-size to 16px (font-size: 16px;). My <h1> being 2em would inherit a size of 32px, because 2em is twice the size of 1em. In this case 1em=16px so 2em=2x16px=32px. Now if you create an HTML document with the following

<body>
<h1>Hello world</h1>
<p>Lorem ipsum</p>
</body>

Then you define following CSS rule.

body {font: normal 16px Arial, Helvetica, sans-serif;}

Open the page in a web browser (Chrome) and open the browsers development tools (ctrl+shift+I), you'll see the default font-size for an <h1> is 2em. You will also see on the styles tab that it is "Inherited from body". While still in the Development Tools for this scenario you can see on the Box Model diagram that the <h1> margin is 21.440px on the top and bottom margins. If you look in the CSS defaults for <h1> you can see the margin-block-start: 0.67em; and margin-block-end: 0.67em; Remember sizing is relative to the font size of the parent element, so 0.67em is relative to the <h1> font size not the font size of the <body>, you can verify this with a little math, 0.67em x 32px=21.440px and this is the size of the margin of the <h1> in the Box Model diagram. For more information try http://www.123webconnect.com/convert-px-em.php

Aras answered 13/2, 2019 at 8:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.