Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is height in em?

Tags:

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?

like image 511
happyhardik Avatar asked Aug 09 '10 07:08

happyhardik


People also ask

What is em height CSS?

The em is simply the font size. In an element with a 2in font, 1em thus means 2in. Expressing sizes, such as margins and paddings, in em means they are related to the font size, and if the user has a big font (e.g., on a big screen) or a small font (e.g., on a handheld device), the sizes will be in proportion.

How is em calculated?

An em is equal to the computed font-size of that element's parent. For example, If there is a div element defined with font-size: 16px then for that div and for its children 1em = 16px . If font-size is not defined explicitly, that element will inherit it from the parent element.

What is VH and em?

EM: Relative to the parent element. REM: Relative to the root element (HTML tag) %: Relative to the parent element. VW: Relative to the viewport's width. VH: Relative to the viewport's height.

What is em spacing?

An em space is a typographical space measuring one em in width. Traditionally, for a font that uses the Latin alphabet, an em space is approximately the width of a capital letter M.


1 Answers

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

like image 160
simplyharsh Avatar answered Oct 20 '22 12:10

simplyharsh