Is it wise to use fractional / decimal pixels for borders in css?

13,685

You can use it, but most browsers will round pixel value.

http://www.w3.org/TR/2011/REC-CSS2-20110607/syndata.html#values

http://ejohn.org/blog/sub-pixel-problems-in-css

http://cruft.io/posts/percentage-calculations-in-ie/

EDIT: Remember that one CSS pixel is not always equal to one physical screen pixel: A pixel is not a pixel is not a pixel

Share:
13,685
someoneHere
Author by

someoneHere

Updated on June 09, 2022

Comments

  • someoneHere
    someoneHere about 2 years

    I have various instances in my design that call for

    border-right: 1.5px solid black;
    border-bottom: 1.5px solid black;
    

    etc...

    I also have design that needs thinner lines: at 1px.

    However, it seems the browser may round the decimal, as I'm not seeing much differentiation between the two (if any).

    Should I just be using 2px and 1px instead, or is there a better way to pull this off?

    A designer I'm helping is very adamant about the 1.5px line width.

    Any help, much appreciated.

  • someoneHere
    someoneHere over 8 years
    Is there another value I could use? Pt , em, etc? Use css transform / scale?
  • zucker
    zucker over 8 years
    @someoneHere Yes, you can use decimal value with percent, pt, em. But sometimes it can works inconsistently for different browsers.