JavaScript Screen pixelDepth Property

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

What You’ll Learn

Screen.pixelDepth is a read-only instance property that returns the bit depth of the screen. Learn what the number means, why many browsers report 24 for CSSOM compatibility, how it relates to colorDepth, and the MDN color-choice pattern—with five examples and try-it labs.

01

Kind

Read-only property

02

Returns

Number (bits)

03

Access

window.screen

04

Common

Often 24

05

Related

colorDepth

06

Status

Baseline widely

Introduction

Bit depth describes how many bits are used per pixel for color. A higher depth can represent more colors. Historically, pages sometimes chose a simpler text or background color on low-depth displays.

Today you usually see 24. MDN notes that, per the CSSOM, some implementations return 24 for compatibility even when the hardware differs.

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

Think of pixelDepth as a screen capability hint, not proof of exact GPU bit depth. Prefer modern CSS and images that work on typical 24-bit displays.

Understanding the Property

MDN: Screen.pixelDepth returns the bit depth of the screen. Per the CSSOM, some implementations return 24 for compatibility reasons.

  • Instance — on window.screen.
  • Read-only — you cannot assign to pixelDepth.
  • Number — typically bits per pixel (for example 24).
  • Compatibility — browsers may normalize the reported value to 24.

📝 Syntax

JavaScript
const depth = window.screen.pixelDepth;
// same as:
const depth2 = screen.pixelDepth;

Value

A number representing the screen’s bit depth.

🔄 pixelDepth vs colorDepth

Both properties describe how colorful the screen can be. On modern browsers they usually report the same number. When you build a diagnostics panel, log both so learners can see they match.

JavaScript
console.log(screen.pixelDepth, screen.colorDepth);
console.log(screen.pixelDepth === screen.colorDepth);
📌
Teaching tip

Do not rely on a difference between pixelDepth and colorDepth for feature detection unless you have a specific engine target. Prefer treating them as related Screen color metrics.

🎨 MDN Color-Choice Pattern

MDN’s example picks a richer color when bit depth is greater than 8, otherwise a simpler color. Here is a beginner-safe version that sets text color on the page body:

JavaScript
// If there is not adequate bit depth, choose a simpler color
document.body.style.color =
  window.screen.pixelDepth > 8 ? "#FAEBD7" : "white";

With a typical report of 24, the antique-white branch (#FAEBD7 runs. On a rare low-depth display, the code would choose white.

🔢 Common Depth Values (Beginner Guide)

ValueRough meaning
8256 colors (old / specialized displays)
16High color (~65K colors)
24True color (~16.7M colors)—most common report
30 / 32Deep color / with alpha in some contexts

⚡ Quick Reference

GoalCode
Read bit depthscreen.pixelDepth
MDN color branchpixelDepth > 8 ? "#FAEBD7" : "white"
Compare colorDepthscreen.pixelDepth === screen.colorDepth
Typical modern value24
MDN statusBaseline Widely available (Jul 2015)

🔍 At a Glance

Four facts about screen.pixelDepth.

Kind
property

Read-only

Type
number

Bit depth

Via
window.screen

Screen object

Status
baseline

Widely available

Examples Gallery

Examples follow MDN Screen.pixelDepth. Your machine will usually print 24.

📚 Getting Started

Read the depth and practice the MDN color-choice branch.

Example 1 — Read pixelDepth

Log the number and its type.

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

How It Works

window.screen.pixelDepth returns a number. On most modern browsers that number is 24.

Example 2 — MDN Color Choice

Pick antique white vs white based on bit depth.

JavaScript
const color =
  window.screen.pixelDepth > 8 ? "#FAEBD7" : "white";

console.log(screen.pixelDepth);
console.log(color);
Try It Yourself

How It Works

Inspired by MDN. With pixelDepth of 24, the richer color branch wins.

📈 colorDepth, Labels & Screen Snapshot

Put pixelDepth next to related Screen metrics.

Example 3 — Compare with colorDepth

On most engines these two match.

JavaScript
console.log(screen.pixelDepth);
console.log(screen.colorDepth);
console.log(screen.pixelDepth === screen.colorDepth);
Try It Yourself

How It Works

Logging both confirms they are related Screen color metrics. See also the colorDepth tutorial.

Example 4 — Friendly Label for Common Depths

Map the number to a beginner-friendly description.

JavaScript
function labelDepth(bits) {
  if (bits < 8) return "very low color";
  if (bits < 16) return "256-color class";
  if (bits < 24) return "high color";
  return "true color (or reported as 24)";
}

const bits = screen.pixelDepth;
console.log(bits);
console.log(labelDepth(bits));
Try It Yourself

How It Works

Labels help learners interpret the number. Keep in mind browsers may report 24 for compatibility even on deeper panels.

Example 5 — Bit Depth Plus Screen Size

A small diagnostics object combining Screen properties.

JavaScript
console.log({
  pixelDepth: screen.pixelDepth,
  colorDepth: screen.colorDepth,
  width: screen.width,
  height: screen.height,
  availWidth: screen.availWidth,
  availHeight: screen.availHeight
});
Try It Yourself

How It Works

Combine bit-depth metrics with size properties like height for a fuller Screen snapshot.

🚀 Common Use Cases

  • Teaching what bit depth means in the browser.
  • Legacy-style color fallbacks when depth is very low (rare today).
  • Diagnostics panels that dump Screen metrics.
  • Comparing pixelDepth with colorDepth in QA notes.
  • Understanding why many engines always report 24.

🔧 How It Works

1

Display has a bit depth

Hardware / OS know how colors are represented.

Display
2

Browser exposes Screen.pixelDepth

May return a compatibility value such as 24 (CSSOM).

Screen
3

You read the number

Optional color branches or diagnostics.

Read
4

Prefer robust visuals

Design for typical 24-bit reports; treat low depth as rare.

📝 Notes

  • Baseline Widely available (MDN, since July 2015).
  • Not Deprecated, Experimental, or Non-standard — no status banner required.
  • Read-only — do not assign to pixelDepth.
  • Some implementations return 24 for CSSOM compatibility.
  • Related: colorDepth, orientation, Window hub, JavaScript hub.

Universal Browser Support

Screen.pixelDepth is Baseline Widely available across modern browsers (MDN: since July 2015). Logos use the shared browser-image-sprite.png sprite from this project. Some engines always report 24 for compatibility.

Baseline · Widely available

Screen.pixelDepth

Read-only screen bit depth — commonly 24 on modern browsers.

Universal Widely available
Google Chrome Full support · Often reports 24
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
pixelDepth Excellent

Bottom line: Use screen.pixelDepth as a capability hint. Expect 24 on most browsers; compare colorDepth for diagnostics; do not overfit UI to rare low-depth values.

Conclusion

window.screen.pixelDepth returns the screen’s bit depth as a number. Learn the MDN color-choice pattern, expect 24 on modern browsers, and treat the value as a hint alongside colorDepth and size metrics.

Continue with width, colorDepth, Window methods, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Read screen.pixelDepth for a simple capability hint
  • Expect 24 on typical modern browsers
  • Log colorDepth too when debugging Screen metrics
  • Design colorful UIs that work without rare low-depth branches
  • Check MDN compatibility notes when values look “stuck” at 24

❌ Don’t

  • Assign to pixelDepth (it is read-only)
  • Assume the number always matches exact hardware bit depth
  • Build critical UX that only works when depth is exactly 32
  • Confuse bit depth with screen resolution (width / height)
  • Ignore CSS and media features for responsive design

Key Takeaways

Knowledge Unlocked

Five things to remember about pixelDepth

Screen bit depth as a simple number.

5
Core concepts
🔢 02

Number

bit depth

Value
🔄 03

Often 24

CSSOM compat

Note
📄 04

colorDepth

usually matches

Related
🎯 05

Baseline

widely available

Status

❓ Frequently Asked Questions

A read-only number: the bit depth of the screen. Access it as window.screen.pixelDepth. Many browsers report 24 for CSSOM compatibility.
No. MDN marks Screen.pixelDepth as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
MDN: per the CSSOM, some implementations return 24 for compatibility reasons. Check the compatibility table for engines that differ.
Both describe screen color capability. On most modern browsers they report the same number. Treat them as related diagnostics, not as a guarantee of exact hardware bit depth.
No. It is read-only. You read the number; you do not assign to it.
MDN shows that pattern to pick a richer vs simpler color. Today almost all user screens report at least 24, so the low-depth branch is rare—but it remains a clear teaching example.
Did you know?

Bit depth is about how many colors can be represented per pixel—not how sharp the screen is. Sharpness is more about resolution (width / height) and device pixel ratio.

Next: Screen.width

Learn the full screen width property in CSS pixels.

width →

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