Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a CSS pixel be a fraction?

Tags:

css

w3c

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.

like image 258
Kees C. Bakker Avatar asked Jan 31 '12 13:01

Kees C. Bakker


People also ask

Can you have half a pixel in CSS?

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.

Is there such thing as half a pixel?

There is no such thing as fractional pixel. Pixel is the smallest screen unit.

What is CSS pixel size?

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.

Can you use decimals in CSS?

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.


1 Answers

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.

like image 73
Guffa Avatar answered Oct 19 '22 18:10

Guffa