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
Fundamentals
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.
Concept
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.
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.
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.
Practice
🎨 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.
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.
UniversalWidely available
Google ChromeFull support · Often reports 24
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerSupported in modern IE versions
Supported
pixelDepthExcellent
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.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about pixelDepth
Screen bit depth as a simple number.
5
Core concepts
🎨01
Read-only
on Screen
Kind
🔢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.