An easy way to get the actual pixel width of a screen using JavaScript.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Allows you to get the physical pixel width of a device using JavaScript.

Note: GetDevicePixelWidth includes [GetDevicePixelRatio]:(

Size and delivery

Currently, getDevicePixelWidth.js compresses to around 450 bytes (~0.4 KB), after minify and gzip. To minify, you might try these online tools: [Microsoft Ajax Minifier]:(, [Uglify]:(, [Yahoo Compressor]:(, or Closure Compiler. Serve with gzip compression.


<script type="text/javascript">
	var devicePixelWidth = window.getDevicePixelWidth();

If you want to assume that the user is in landscape mode use the following:

<script type="text/javascript">
	var devicePixelWidth = window.getDevicePixelWidth(true);


GetDevicePixelWidth supports a broad range of browsers and devices (there are currently no known unsupported browsers).