Choosing Between EMs and Pixels for Font Sizes: A 2011 Perspective

In the past, EMs were favored over pixels for font size because they could scale with IE6 while pixels could not. Nowadays, modern browsers can handle pixel-sized font scaling correctly. Another advantage of EMs is that they cascade, unlike pixels.

But if someone is working on web development for modern browsers and does NOT want cascading font sizes, would pixels be the better choice?

I'm trying to consider if there are any other disadvantages to using pixels for font size instead of EMs. Thank you!

Answer №1

Although most modern browsers can zoom in on text that is sized using pixels, not all of them can scale text sized with pixels – it still varies depending on the browser.

For example, in IE8, you can easily zoom in on text without any issues. However, if you try to scale text using the official text size modifier (by going to page -> text size -> largest), it doesn't work properly.

  1. In IE8 - Zoom works, but scaling does not
  2. In Firefox 4, beta 12 - Zoom works, but scaling does not
  3. In Google Chrome 10 beta - Zoom works, but scaling does not

Many organizations I collaborate with use the official text size modifier as part of their user/group settings management. When setting up accounts for users, they often pre-configure it using this setting. Personally, I prefer using EMs because PX doesn't scale consistently across different platforms.

And a few words from the W3C:

Units: avoid absolute length units for screen display

  • Avoid specifying font-size in pt or other absolute length units for screen stylesheets, as they render inconsistently and cannot be resized by the User Agent (e.g., browser). Instead, use relative length units like percent or em.

Reference: http://www.w3.org/QA/Tips/font-size

Answer №2

One disadvantage of specifying font size in pixels is the difficulty in uniformly adjusting text sizes across a website post-development.

If you establish an absolute font-size for the body element and utilize Ems for other text properties, modifying the entire site's text sizes can be achieved by simply changing the body element's font size.

It is safe to assume that many users are unfamiliar with adjusting only text sizes using browser zoom features, yet web designers still strive to maintain consistency between text, page components, and overall layout proportions.

Answer №3

Every up-to-date browser comes equipped with full-page zoom capabilities, making pixels the preferred unit of measurement for achieving a harmonious text size and graphic display on webpages (which are pixel-dependent).

Answer №4

Here is my approach:

  • Start by incorporating a reset.css file (I recommend Eric Meyer's )
  • Establish default styles for elements like h1, h2, a, etc.
  • If necessary, use EM units for sizing.

I have gained valuable experience in ensuring cross-browser compatibility, including on mobile devices, throughout my web development journey.

Give it a try :)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Missing Bootstrap 3 Options Menu trip away

I created a table with 4 columns using the Bootstrap 3 grid system. Instead of utilizing the col-xs-* classes, which work well on mobile devices, I opted for the col-md-* classes. This decision was based on my preference to have larger and more visible ico ...

Avoiding the selection of HTML canvas objects

I am currently working on customizing my homepage with an interactive animation. However, I am facing some challenges in integrating it seamlessly into the page. You can view the progress at . My main issue is preventing the canvas object from being select ...

Forming a space between borders

I'm attempting to create a space within a div's border that can accommodate an image, much like so: Is there a method to achieve this using only CSS? The only solution I have found is: .box { background: url(img.png) bottom left; border ...

full-page overlay is covering the entire screen

Is there a CSS-based solution to create an overlay that remains visible even when the page is scrolled down? I want to use this overlay behind a popup. Using JavaScript to set the height of the overlay based on the page's content is one option, but I& ...

Deletion of a custom function in JavaScript

I have written some basic code to generate and remove an image using functions. Specifically, I need help with removing the image created by the function Generate() when a button linked to the function Reset1() is clicked. Here's the code snippet for ...

Exploring Vue and Webpack's tree shaking functionality, side effects management, and its impact on CSS: Loading unused component CSS

We are currently grappling with the challenge of effectively implementing tree shaking for CSS within Vue Single File Components using Webpack. Within our package.json file, we have specified: "sideEffects": ["*.css", "*.less","*.vue"], which appears to b ...

I'm having trouble locating the HTML link in my text

I've recently started coding and I'm facing an issue. I can't seem to figure out why a link named "Food Taxi" isn't showing up. I added an href tag, but it's still not linking properly. I've tried moving some code around witho ...

Control the line height in DataTables

Is there a way to adjust the line height for a tr using either DataTables settings or CSS? I've attempted different methods, but nothing seems to change the line-height. https://i.sstatic.net/GwFaD.png Table CSS ...

Adjusting the background color using CSS according to the browser's dimensions

I'm having trouble identifying the issue with this code. The background color remains white and doesn't change as expected. <style type="text/css"> h1 { position: absolute; text-align: center; width: 100%; ...

Encountering the error message "AngularJS error: $(...).modal is not a function" after updating from Bootstrap 3.3.6 to version 4.0

Since updating the bootstrap version in my application from 3.3.6 to 4, I've been encountering an error stating that $(...).modal is not a function. This was previously working fine before the update. angular.js:14700 TypeError: $(...).modal is n ...

Creating a simulated textarea with a scrollbar and dynamically refreshing the content

Due to limitations on markup content inside <p> tags, I have decided to create my own custom textbox. This textbox will function as a console where the battle progress is logged. Initially, I attempted using nested divs for each log, but encountered ...

Creating a List with Sublists that are displayed when hovering over the parent List is a key element of effective design

Hovering over 'View Rows' should open up both New Records and Old Records <div> <li>Add Rows</li> <li>DeleteRows</li> <li>View Rows <ul> <li>View New Records</li ...

Parent: Using Flexbox vs Child: Choosing between inline-block or inline elements (Advantages of utilizing CSS3 flexbox?)

I've been exploring the capabilities of CSS3's new "display: flex" property and trying to determine its advantages. So far, I haven't discovered any significant benefits beyond creating a virtual horizontal line within each flex box containe ...

Issue with CSS background scaling bug

Is it possible to make the cloud background scale within the box? The current issue can be viewed here: I have tried various methods to resolve the problem where the background scales even beyond the limited box. However, I could not identify the solutio ...

Abundance of DOM elements - the difference between hidden and display none

When I have numerous DOM elements on my page and assign them all a display: none property, the browser continues to perform quickly (smooth scrolling and snappy page response). But if I hide the elements using visibility: hidden instead, the browser slows ...

Tips for showcasing numerical values using radio buttons

Hello, I am currently working on my project and have a question about calling the ajax function when clicking a button. If(isset($_POST) && ($_POST['GET_PAYMENT'] == '1')) { $totalAmount = $_POST['GET_PAYMENT']; //Total amo ...

Tips for clearing floated images when the sidebar is also floated

Can someone assist me with this code snippet? I am trying to figure out a way to clear the nearest floated block. It seems that whenever I use the clear property, it clears any floated blocks on the page, even if they are in a different div. Here is the ...

Selecting specified elements in Jsoup using CSS selectors

Check out this HTML snippet: <div class="last-minute"> <span>Modulo:</span>4-3-3<p>Mandorlini is hopeful to have Juanito Gomez and Cirigliano back in action after the break. There's no need to worry about Hallfredsson who was ...

Is it possible to apply a margin to <details><summary> elements?

I am struggling with adding a margin to each of the children in my nested <details> elements .container { margin: 20px; } .parent, .child { outline: none; border: none; user-select: none; cursor: pointer; } <div class="container"> ...

Changing the appearance of a radio button dynamically upon clicking

I am currently working on a dynamic pickup date form that utilizes radio buttons. My goal is to change the style of the selected value when a user clicks on it. Below is the code I have tried, but it has not been successful: foreach ($period as $day){ ech ...