JavaScript Screen width Property

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline Widely available
Instance property

What You’ll Learn

Screen.width is a read-only instance property that returns the full width of the screen in CSS pixels. Learn how it differs from availWidth and innerWidth, why OS chrome can shrink available space, and MDN’s classic 1024×768 check—with five examples and try-it labs.

01

Kind

Read-only property

02

Returns

Number (CSS px)

03

Access

window.screen

04

Meaning

Full screen width

05

Twin

screen.height

06

Status

Baseline widely

Introduction

The browser’s screen object describes the display behind your window. screen.width answers: “How wide is the whole screen, in CSS pixels?” That is the full horizontal size of the monitor (or the display associated with this window)—not how wide the current tab is.

Operating systems may keep a vertical strip for themselves (taskbars on the side, docks, and similar chrome). That is why availWidth can be smaller than width. MDN also pairs width with height for crude resolution checks such as “at least 1024×768.”

JavaScript
console.log(window.screen.width);
💡
Beginner tip

screen.width is about the monitor. For the visible page width inside the tab, use window.innerWidth instead. Prefer CSS media queries for most responsive layout.

Understanding the Property

MDN: the Screen.width read-only property returns the width of the screen in CSS pixels.

  • Instance — on the Screen object from window.screen.
  • Read-only — you cannot assign to width.
  • CSS pixels — same unit family as layout sizes (not always hardware pixels).
  • Full width — may be larger than availWidth when OS chrome is reserved.

📝 Syntax

JavaScript
const w = window.screen.width;
// same as:
const w2 = screen.width;

Value

A number: the full screen width in CSS pixels. Compare it with window.screen.availWidth when you care about space left after OS chrome.

📈 width vs availWidth

PropertyMeaning
screen.widthFull screen width in CSS pixels
screen.availWidthWidth available for web content (often minus OS chrome)
screen.heightFull screen height (vertical twin)
window.innerWidthViewport / layout viewport width of this window
📌
MDN note

Not all of the width from screen.width may be available to the window. When other widgets occupy space the window object cannot use, there is a difference between screen.width and screen.availWidth. See also screen.height.

🎨 MDN Minimum Resolution Check

MDN’s teaching example: a crude way to check that the screen is at least 1024×768 CSS pixels.

JavaScript
// Crude way to check that the screen is at least 1024x768
if (window.screen.width >= 1024 && window.screen.height >= 768) {
  console.log("Resolution is 1024x768 or above");
} else {
  console.log("Resolution is below 1024x768");
}

Useful for diagnostics and teaching. For responsive UI, prefer CSS @media queries rather than hard-coding JS resolution gates.

⚡ Quick Reference

GoalCode
Full screen widthscreen.width
Available widthscreen.availWidth
Reserved horizontal pxscreen.width - screen.availWidth
MDN min size checkwidth >= 1024 && height >= 768
This tab’s widthwindow.innerWidth
MDN statusBaseline Widely available (Jul 2015)

🔍 At a Glance

Four facts about screen.width.

Kind
property

Read-only

Type
number

CSS pixels

Via
window.screen

Screen object

Status
baseline

Widely available

Examples Gallery

Examples follow MDN Screen.width. Numbers on your machine will differ by display and OS chrome.

📚 Getting Started

Read the full width and practice the MDN resolution check.

Example 1 — Read width

Log the full screen width in CSS pixels.

JavaScript
console.log(window.screen.width);
console.log(typeof screen.width);
Try It Yourself

How It Works

window.screen is the Screen object. width is a number you can compare with available or viewport widths.

Example 2 — MDN 1024×768 Check

Crude minimum resolution gate using width and height.

JavaScript
if (window.screen.width >= 1024 && window.screen.height >= 768) {
  console.log("Resolution is 1024x768 or above");
} else {
  console.log("Resolution is below 1024x768");
}
Try It Yourself

How It Works

Directly from MDN. Most modern desktops pass; some small phones may not.

📈 Reserved Space, Full Box & Viewport

Put the full width next to related size metrics.

Example 3 — Estimate Reserved Horizontal Space

Difference between full width and available width.

JavaScript
const reserved = screen.width - screen.availWidth;

console.log("full:", screen.width);
console.log("avail:", screen.availWidth);
console.log("reserved:", reserved);
Try It Yourself

How It Works

A positive reserved often means visible side chrome. Many desktops report 0 when taskbars only use vertical space (or auto-hide).

Example 4 — Full Screen Box with height

Report the full screen rectangle.

JavaScript
const box = {
  width: screen.width,
  height: screen.height
};

console.log(box.width + " x " + box.height);
console.log(box.width * box.height);
Try It Yourself

How It Works

width and height describe the full display size. Pair with availWidth / availHeight for the usable box.

Example 5 — Screen Width vs Window Viewport

Do not mix up monitor width with this tab’s viewport.

JavaScript
console.log({
  screenWidth: screen.width,
  availWidth: screen.availWidth,
  innerWidth: window.innerWidth,
  outerWidth: window.outerWidth
});
Try It Yourself

How It Works

innerWidth / outerWidth describe this window. screen.width describes the display. Resize the browser and only the window values change.

🚀 Common Use Cases

  • Logging full display resolution for diagnostics or QA.
  • Teaching crude minimum-resolution checks (MDN 1024×768 pattern).
  • Comparing with availWidth to see reserved horizontal chrome.
  • Pairing with screen.height for full screen size.
  • Contrasting monitor width with window.innerWidth for beginners.

🔧 How It Works

1

OS knows the display size

Full resolution plus which chrome stays always visible.

OS
2

Browser builds Screen

Exposes width, availWidth, height, availHeight, and more.

Screen
3

You read width

Gets full CSS-pixel horizontal size of the screen.

Read
4

Compare with avail / viewport

Use availWidth for usable space; innerWidth for this tab.

📝 Notes

  • Baseline Widely available (MDN, since July 2015).
  • Not Deprecated, Experimental, or Non-standard — no status banner required.
  • Read-only — do not assign to width.
  • Not the same as window.innerWidth (viewport of this window).
  • Related: pixelDepth, height, availWidth, Window hub.

Universal Browser Support

Screen.width is Baseline Widely available across modern browsers (MDN: since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.

Baseline · Widely available

Screen.width

Full screen width in CSS pixels — often larger than availWidth when OS chrome is reserved.

Universal Widely available
Google Chrome Full support · Desktop & Mobile
Full support
Mozilla Firefox Full support · Desktop & Mobile
Full support
Apple Safari Full support · macOS & iOS
Full support
Microsoft Edge Full support · Chromium
Full support
Opera Full support · Modern versions
Full support
Internet Explorer Supported in modern IE versions
Supported
width Excellent

Bottom line: Use screen.width for full display width; use availWidth for available horizontal space; use innerWidth for this window’s viewport; prefer CSS media queries for layout.

Conclusion

window.screen.width is the full horizontal size of the screen in CSS pixels—sometimes a bit more than availWidth when OS chrome is always visible. Use it for display metrics and comparisons, not as a substitute for viewport width or CSS layout.

Continue with lockOrientation(), height, Window methods, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Read screen.width for full display width
  • Compare with availWidth to see reserved chrome
  • Pair with screen.height for full screen size
  • Use innerWidth for layout inside the current tab
  • Prefer CSS media queries for responsive design

❌ Don’t

  • Assign to width (it is read-only)
  • Confuse it with window.innerWidth
  • Hard-code JS resolution gates for all layout decisions
  • Assume side taskbars always subtract the same number of pixels
  • Ignore availWidth when planning secondary window sizes

Key Takeaways

Knowledge Unlocked

Five things to remember about width

Full screen width in CSS pixels.

5
Core concepts
📈 02

CSS pixels

full screen width

Value
03

≥ availWidth

may include chrome

Rule
📐 04

Twin

screen.height

Pair
🎯 05

Baseline

widely available

Status

❓ Frequently Asked Questions

A read-only number: the full width of the screen in CSS pixels. Access it as window.screen.width.
No. MDN marks Screen.width as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
screen.width is the full screen width. availWidth is the space available for web content and is never larger—often smaller when OS chrome reserves horizontal space.
No. width is the monitor’s full width. innerWidth is this browser window’s viewport width and changes when you resize the tab.
No. It is read-only. You read the value; you do not assign to it.
Use screen.height for the full screen height in CSS pixels, the vertical twin of width.
Did you know?

Multi-monitor setups still expose a single window.screen for the display associated with the window. Moving a window to another monitor can change the reported width when that display has a different resolution.

Next: Screen.lockOrientation()

Learn the deprecated non-standard orientation lock method.

lockOrientation() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful