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.
On high DPI/PPI devices, a single CSS pixel may become two physical pixels. A 4px measure may become 6px, or 8px. Fractional pixels are actually quite useful as a 0.5px border should round up to 1px at 1.0 scale factor, and remain 1px (as thin as possible) at 1.5 or 2.0 scale.
There is no such thing as fractional pixel. Pixel is the smallest screen unit.
The CSS pixel (px) The reference pixel is the visual angle of one pixel on a device with a pixel density of 96 DPI and a distance from the reader of an arm's length. The proper dimension of a CSS pixel is actually dependent on the distance between you and the display.
Although you can use decimal places in CSS like 100.0% in reality it best to keep to real numbers for percentages and only upto one decimal place with standard linear integer values. Your 2.9… probably would be read as 3. Furthermore you have to remember many elements use padding, margins and borders.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With