Can a CSS pixel be a fraction?

Kees C. Bakker picture Kees C. Bakker · Jan 31, 2012 · Viewed 37.9k times · Source

Can a CSS px be a fraction? Is it allowed by the standards? And if so, do the major browsers support it?

Let's back the answers up with documentation, folks.

Answer

Guffa picture Guffa · Jan 31, 2012

Yes, you can specify fractional pixels. As this has been part of CSS since the very first version, it should be well supported by any browser that supports CSS at all.

Reference: CSS 2.1: 4.3.2 Lengths

"The format of a length value (denoted by <length> in this specification) is a <number> (with or without a decimal point) immediately followed by a unit identifier (e.g., px, em, etc.)."

When the elements are displayed on the screen, most browsers will naturally round the position to the nearest pixel when using 100% zoom level. On higher zoom levels you will notice that fractional pixel values are recognized.