Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibraryWebsite Development and Maintenance

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

The Biggest Reason for CSS Points Instead of Pixels

Some years ago, PC screen resolution was 96 pixels per inch, Macintosh screen resolution was 72 pixels per inch. Screens for other operating systems generally had one of those resolutions.

At that time, it was safe to specify pixels for CSS dimensions and font sizes. There wasn't enough difference between the resolutions to matter for many or most design applications.

Then came higher resolutions; especially on mobile devices but also on desktop and laptop computers. And that's the reason, the biggest reason, for using points or other non-pixel measurements instead of pixels.

The 84 pixels (midway between 72 and 96) that measured close to an inch on both previous resolutions may now measure only half an inch on double-resolution mobile devices.

Some device manufacturers automatically adjust pixel measurements to nearly what it would be for a desktop screen resolution — so the 84 pixels may still appear to be about an inch. Otherwise, their users would see things at half size. But don't depend on the automatic adjustment continuing indefinitely.

Eventually, some or all devices and computers won't make the pixel dimension and font size adjustments. I expect it to happen after the majority of websites have replaced the CSS pixel measurement with resolution-independent measurements.

Don't get caught with pixels.

Change your CSS from pixels ("px" in CSS notation) to absolute distance and relative size so your pages don't depend on screen resolution to display properly. It might not be urgent, yet, but prudent to get it done as you can.

For some things, like images with exact pixel dimensions, the pixel measurement may still be required. For most things, though, non-pixel measurements are preferred.

Computer and device resolutions are likely to continue evolving. I'm unaware of any resolution standard. Manufactures create and will continue to create the screen resolutions they think will sell the most devices.

Therefore, to protect your websites from device manufacturer whimsy, use non-pixel CSS measurements. That would be absolute linear measurements for dimensions and distances and it would be relative measurements for fonts and sizes related to fonts.

Let's talk about non-pixel CSS measurements that are available. Some or all will be familiar to you if you've been doing website design.

There are relative measurements and there are absolute measurements.

I'll mention only the measurements that have been available in browsers pretty much from the get-go. Measurements available in later browsers and CSS versions may be addressed in other articles.

CSS NotationWhat it is
px Means pixels — the one not to use.
em

That's the entire spelling of an em, pronounced like the letter "M." It has history in typography. An em is the size of the font being used.

Generally, the capital letter "M" of the font is the same width as the size of the font. But not always. So, instead of thinking "width of M," think "size of font."

% It means "percent" or "percentage." The measurement equals the specified percent of the container width or height or the font size it relates to. 50% of 1 em is ½ the current font size. 50% of 11 millimeters is 5.5 millimeters.
mm It means an absolute measurement of a millimeter.
cm It means an absolute measurement of a centimeter or 10 millimeters.
in It means an absolute measurement of an inch.
pt It means an absolute measurement of a point (a typography measurement). There are 72 points in an inch.
pc It means an absolute measurement of a pica or 12 points. There are 6 picas in an inch.

Use the measurements you're most comfortable with or that makes the most sense for the project you're focused on.

I generally use ems and points, now that I'm weaning myself off pixels. Although I do use inches occasionally for things like column widths.

CSS Measurement Examples

Although this isn't a tutorial on how to use measurements, examples are provided for a quick visual comparison.

First, pixel, em, and percent as applied to font size.

font-size:14px;
font-size:1em;
font-size:1.5em;
font-size:100%;
font-size:150%;

The percentage sizes in the above examples are calculated on a font size of 1 em.

Now, examples of pixel, point, pica, inch, centimeter, millimeter, and percentage as applied to an absolute measurement.

width:150px;
width:120pt;
width:10pc;
width:1.5in;
width:4cm;
width:40mm;
width:50%

The percentage size in the example is calculated on a 40 millimeter width.

The important point: Technology continues to evolve. Computer and device resolutions will continue to change. The used-to-be-standard pixel measurement is losing its status.

Use non-pixel measurements, instead.

(This article first appeared in Possibilities ezine.)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC