Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use em or px? [closed]

Tags:

css

I'm starting off a new web project and I'm wondering whether to use em or px for the layout and font sizes.

Despite the fact that most browsers now support text and image zooming regardless of whether fonts are defined in px or em, the community support for using em is still strong.

But there are 2 problems I see with using em.

First is the problem with large and wide monitors - often this results in text running miles and miles across the screen, which is very difficult to read as you read down the page.

Secondly, what if your site needed to integrate a Flash component? If you want the Flash component to fit exactly inside a div (e.g the main container of the site) that is defined in em, how would you go about it since Flash components are measured in px?

Is there a compelling reason to use EM over PX, really?

like image 427
helloworlder Avatar asked Dec 19 '09 12:12

helloworlder


2 Answers

First is the problem with large and wide monitors - often this results in text running miles and miles across the screen, which is very difficult to read as you read down the page.

Using em or px, you can still define a width (or max-width) to your layout.

Secondly, what if your site needed to integrate a Flash component? If you want the Flash component to fit exactly inside a div (e.g the main container of the site) that is defined in em, how would you go about it since Flash components are measured in px?

To fit exactly, you can still use 100% width, or maybe I did not understand your point.


In theory, using em instead of px will allow your layout to be easily sizable based on user preferences.

But today, modern browsers can resize px layouts as well as em layouts so it might not be as relevant as it was some years ago.

like image 51
Vincent Robert Avatar answered Sep 20 '22 02:09

Vincent Robert


When you use relatively sized instead of fixed fonts, then the major benefit is that a (optically disabled) visitor can zoom in/out the webpage including the fonts. It's all about web accessibility.

like image 44
BalusC Avatar answered Sep 18 '22 02:09

BalusC