[X]

Best Viewed At

browser tricks 1997 still works

Reads the visitor's screen size and tells them off if it is not 800x600.

In 2026: Works, but screen.width was always the whole display, never the browser window, and on a HiDPI screen it now reports CSS pixels rather than hardware pixels. Use window.innerWidth if you want the size of the actual viewport.

Where it came from: Netscape JavaScript 1.2 screen object, 1997.
MDN

<script language="JavaScript">
document.write("Your screen is " + screen.width + "x" + screen.height
             + " at " + screen.colorDepth + " bit colour.<br>");

if (screen.width < 800) {
  document.write("<b>This site is best viewed at 800x600 or higher!</b>");
}
</script>

<!-- The size that actually matters is the window, not the screen.
     Read it after load: during parsing this frame has no size yet, so a
     document.write here would report 0x0. -->
<p id="vp" style="font:13px Verdana"></p>
<script>
window.onload = function () {
  document.getElementById("vp").innerHTML = "Your browser window is "
    + window.innerWidth + "x" + window.innerHeight;
};
</script>
sandboxed demo · breaks nothing but itselfrestart

More in browser tricks

view the whole library ›