pixelRound

Commons
stable

Round a sub-pixel value to the nearest physical pixel boundary using `devicePixelRatio`. Prevents blurry rendering on high-DPI screens when positioning overlays and tooltips.

API

Signature

Full TypeScript signature sourced from the util file.

typescript

API

Parameters

Input parameters accepted by this util.

val
required
number
A CSS pixel value (fractional or whole). Multiplied by `devicePixelRatio`, rounded, then divided back to the nearest physical-pixel boundary.

API

Return value

The value returned by this util.

The input rounded to the nearest physical pixel grid line in CSS pixel units.

Usage

Examples

Ready-to-paste usage snippets.

Round to physical pixel (2x display)

typescript