I remember having read here on SO that pixel fractions should be generally avoided in CSS because browsers tend to round them to full pixels.
And indeed, the below example shows how 0.3
pixels are rounded to a full pixel:
span {
border: 0.3px solid black;
}
<span>Lorem ipsum.</span>
I am very surprised because I seem to have found a counterexample:
span {
color: white;
-webkit-text-stroke: 0.3px black;
}
<span>Lorem ipsum.</span>
Compare with 1px
:
span {
color: white;
-webkit-text-stroke: 1px black;
}
<span>Lorem ipsum.</span>
I'm not complaining that it happens, on the contrary it's almost a lifesaver for me, but I'd like to understand why does it happen.
- When are browsers rounding pixel fractions to full pixels? And when are they not? What are the rules here?
- Can I rely on browsers not rounding
0.3px
to1px
in the above example? Is this behavior consistent across browsers? Or is relying on this behavior a recipe for trouble? - HOW does this happen at all? On laptops a pixel should be indivisible bc of hardware (monitor) limitations?