Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between px, em and ex?

Tags:

css

What is the difference between px, em and ex? And when you define font-size in CSS, do you use px, pt or em?

like image 687
manraj82 Avatar asked Mar 05 '10 09:03

manraj82


People also ask

What is em and ex?

em: one "em" is defined to be the value of font-size for a given font. If the font-size of an element is 14 pixels, then for that element, 1em is equal to 14 pixels. ex: refers to the height of a lowercase x in the font being used.

What does 1em mean?

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.

What is the difference between px em and REM?

Margin for typography ( rem ) - Case for margin between heading and paragraph. Padding for typography ( em ) - Case for different button size. Font size ( em or % ) - Case for heading font size and secondary font size. Root font size ( px ) - It is the root!


1 Answers

em : the font-size of the relevant font
ex : the x-height of the relevant font
px : pixels, relative to the viewing device

like image 197
Shivkant Avatar answered Sep 18 '22 20:09

Shivkant