Screen.colorDepth is a read-only instance property that returns the color depth of the screen. Learn what the number means, why many browsers report 24 for compatibility, how it relates to pixelDepth, and the classic MDN low-color branch—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
pixelDepth
06
Status
Baseline widely
Fundamentals
Introduction
Color depth describes how many bits are used to store each pixel’s color. A higher depth can represent more colors. Historically, web apps sometimes served a simpler palette on very low-color displays.
Today you usually see 24 (true color). MDN notes that, per the CSSOM, some implementations return 24 for compatibility even when the hardware differs.
JavaScript
console.log(window.screen.colorDepth);
💡
Beginner tip
Think of colorDepth as a screen capability hint, not as proof of exact GPU bit depth. Prefer modern CSS and images that work on typical 24-bit displays.
Concept
Understanding the Property
MDN: the Screen.colorDepth read-only property returns the color depth of the screen. Per the CSSOM, some implementations return 24 for compatibility reasons.
Instance — on window.screen.
Read-only — you cannot assign to colorDepth.
Number — typically bits per pixel (for example 24).
Compatibility — browsers may normalize the reported value to 24.
Your browser may still print 24 even on a deeper display because of the CSSOM compatibility behavior MDN mentions.
Related
🔄 colorDepth and pixelDepth
screen.pixelDepth is a closely related Screen property. On modern browsers it often equals colorDepth. When you log diagnostics, print both so learners can see they usually match.
window.screen.colorDepth returns a number. On most modern browsers that number is 24.
Example 2 — MDN Low-Color Branch
Choose a simple vs colorful experience based on depth.
JavaScript
// Check the color depth of the screen
if (window.screen.colorDepth < 8) {
console.log("Use low-color version of page");
} else {
console.log("Use regular, colorful page");
}
Logging both helps confirm they are related Screen color metrics. Do not rely on a difference between them for feature detection unless you have a specific engine target.
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.colorDepth;
console.log(bits);
console.log(labelDepth(bits));
Screen.colorDepth 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.colorDepth
Read-only screen color 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
colorDepthExcellent
Bottom line: Use screen.colorDepth as a capability hint. Expect 24 on most browsers; compare pixelDepth for diagnostics; do not overfit UI to rare low-color values.
Wrap Up
Conclusion
window.screen.colorDepth returns the screen’s color depth as a number. Learn the MDN low-color pattern, expect 24 on modern browsers, and treat the value as a hint alongside pixelDepth and size metrics.
Read screen.colorDepth for a simple capability hint
Expect 24 on typical modern browsers
Log pixelDepth too when debugging Screen metrics
Design colorful UIs that work without relying on rare low-color branches
Check MDN compatibility notes when values look “stuck” at 24
❌ Don’t
Assign to colorDepth (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 color depth with screen resolution (width / height)
Ignore CSS and media features for responsive design
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about colorDepth
Screen color depth as a simple number.
5
Core concepts
🎨01
Read-only
on Screen
Kind
🔢02
Number
color depth bits
Value
🔄03
Often 24
CSSOM compat
Note
📄04
pixelDepth
usually matches
Related
🎯05
Baseline
widely available
Status
❓ Frequently Asked Questions
A read-only number representing the color depth of the screen (typically bits per pixel). Access it as window.screen.colorDepth.
No. MDN marks Screen.colorDepth 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. Prefer treating 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 for a low-color fallback. Today almost all user screens report at least 24, so the low-color branch is rare—but it remains a clear teaching example.
Did you know?
Color 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.