JavaScript Screen colorDepth Property

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

What You’ll Learn

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

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.

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.

📝 Syntax

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

Value

A number representing the screen’s color depth.

🎨 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 channel in some contexts

Your browser may still print 24 even on a deeper display because of the CSSOM compatibility behavior MDN mentions.

🔄 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.

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

⚡ Quick Reference

GoalCode
Read color depthscreen.colorDepth
MDN low-color checkif (screen.colorDepth < 8) { … }
Compare pixelDepthscreen.colorDepth === screen.pixelDepth
Typical modern value24
MDN statusBaseline Widely available (Jul 2015)

🔍 At a Glance

Four facts about screen.colorDepth.

Kind
property

Read-only

Type
number

Color depth

Via
window.screen

Screen object

Status
baseline

Widely available

Examples Gallery

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

📚 Getting Started

Read the depth and practice the classic MDN check.

Example 1 — Read colorDepth

Log the number and its type.

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

How It Works

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");
}
Try It Yourself

How It Works

Directly from MDN. With colorDepth of 24, the else branch runs.

📈 pixelDepth, Labels & Screen Snapshot

Put colorDepth next to related Screen metrics.

Example 3 — Compare with pixelDepth

On most engines these two match.

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

How It Works

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));
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 — Color Depth Plus Screen Size

A small diagnostics object combining Screen properties.

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

How It Works

Combine color metrics with availWidth / availHeight for a fuller Screen snapshot.

🚀 Common Use Cases

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

🔧 How It Works

1

Display has a color capability

Hardware / OS know how colors are represented.

Display
2

Browser exposes Screen.colorDepth

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

Screen
3

You read the number

Optional branches or diagnostics.

Read
4

Prefer robust visuals

Design for typical 24-bit reports; treat low-color 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 colorDepth.
  • Some implementations return 24 for CSSOM compatibility.
  • Related: availWidth, availHeight, Window hub, JavaScript hub.

Universal Browser Support

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.

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
colorDepth Excellent

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.

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.

Continue with height, availHeight, Window methods, or the JavaScript hub.

💡 Best Practices

✅ Do

  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about colorDepth

Screen color depth as a simple number.

5
Core concepts
🔢 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.

Next: Screen.height

Learn the full screen height property in CSS pixels.

height →

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