navigator.hardwareConcurrency returns how many logical processors the browser reports. Learn physical vs logical cores, Worker pool sizing, safe caps, five examples, and try-it labs.
01
Kind
Read-only property
02
Returns
Number
03
Baseline
Widely available
04
Means
Logical CPUs
05
Use
Worker pools
06
Range
1 … N
Fundamentals
Introduction
Heavy JavaScript on the main thread freezes the UI. Web Workers move work off the main thread — and the next question is: how many workers should I start?
navigator.hardwareConcurrency answers with a number: the logical processors available to run threads. A four-core CPU might report 8 if each core runs two threads. That number is a practical hint for parallel Worker pools.
💡
Hint, not a lab measurement
MDN notes the browser may report a lower count than the true hardware so it better matches how many Workers can run well at once. Treat it as guidance, not an absolute core census.
Concept
Understanding the hardwareConcurrency Property
Think of it as “how many threads can usefully run at once before they start fighting for the same cores?”
Logical processors — often higher than physical cores (hyper-threading / SMT).
Value — a number from 1 up to the reported logical count.
Browser discretion — may under-report for a more realistic Worker budget.
Main use — size a Worker pool (MDN’s classic example).
Baseline — Widely available across modern browsers (MDN, since about March 2022).
Foundation
📝 Syntax
General form of the property:
JavaScript
navigator.hardwareConcurrency
Value
A number between 1 and the number of logical processors the user agent reports.
Common patterns
JavaScript
// Read the count:
console.log(navigator.hardwareConcurrency);
// Cap workers so a 32-core machine does not spawn 32 Workers:
const workers = Math.min(navigator.hardwareConcurrency || 4, 8);
// MDN-style pool sketch:
const workerList = [];
for (let i = 0; i < navigator.hardwareConcurrency; i++) {
workerList.push({ id: i, inUse: false });
}
Cheat Sheet
⚡ Quick Reference
Goal
Code
Read logical CPUs
navigator.hardwareConcurrency
Type check
typeof navigator.hardwareConcurrency === "number"
Safe default
navigator.hardwareConcurrency || 4
Cap pool size
Math.min(navigator.hardwareConcurrency, 8)
Leave one core free
Math.max(1, navigator.hardwareConcurrency - 1)
Status (MDN)
Baseline Widely available
Snapshot
🔍 At a Glance
Four facts to remember about navigator.hardwareConcurrency.
Returns
number
Logical CPUs
Baseline
widely
Since ~Mar 2022
Exact?
no
May under-report
Best for
Worker pools
Parallel work
Compare
📋 hardwareConcurrency vs deviceMemory
hardwareConcurrency
deviceMemory
Measures
Logical CPU threads
Approximate RAM (GiB)
Type
Number (cores)
Number (GiB buckets)
Baseline
Widely available
Not Baseline (limited)
Typical use
How many Workers
How heavy the page can be
Combine?
Yes — low cores and low memory → lighter workload
Hands-On
Examples Gallery
Examples follow MDN navigator.hardwareConcurrency patterns for reading cores and sizing Worker pools. Prefer Try It Yourself to see your machine’s reported count.
📚 Getting Started
Read the count and turn it into a friendly message.
Example 1 — Read Logical Processors
Log the number of logical processors the browser reports.
High-core machines can report 16+. Capping avoids memory spikes from dozens of Workers.
Example 4 — Worker Pool Plan (MDN Style)
Build a pool record for each logical processor — same idea as MDN’s Worker example.
JavaScript
const workerList = [];
for (let i = 0; i < navigator.hardwareConcurrency; i++) {
workerList.push({
id: i,
// In a real app: worker: new Worker("cpu-worker.js"),
inUse: false
});
}
console.log("planned workers: " + workerList.length);
console.log(JSON.stringify(workerList.slice(0, 3)));
navigator.hardwareConcurrency is Baseline Widely available across modern browsers (MDN: since about March 2022). Use it to size Worker pools, and still apply a max cap for safety.
✓ Baseline · Widely available
Navigator.hardwareConcurrency
Read the logical processor count, cap your Worker pool, and keep heavy work off the main thread.
UniversalWidely available
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
hardwareConcurrencyExcellent
Bottom line: Use hardwareConcurrency as a Worker-sizing hint. Cap the pool and leave headroom for the UI thread.
Wrap Up
Conclusion
navigator.hardwareConcurrency tells you how many logical processors the browser thinks you can use. Size Worker pools from that number, apply a sensible cap, and remember the value may be lower than “real” hardware cores.
Combine with memory / network hints for heavy jobs
Terminate idle Workers when you are done
❌ Don’t
Assume it equals physical core count
Spawn dozens of Workers on high-core PCs
Block the main thread “because Workers exist”
Ignore Worker errors and cleanup
Use it as a unique device fingerprint
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about hardwareConcurrency
Baseline logical-CPU count for Worker pool sizing.
5
Core concepts
💻01
Returns
number
Type
⚙02
Means
Logical CPUs
Threads
👥03
Use
Worker pools
Parallel
📈04
Tip
Cap the max
Safety
✅05
Status
Baseline
Wide
❓ Frequently Asked Questions
It is a read-only Navigator property that returns the number of logical processors available to run threads on the user’s computer — useful for sizing Web Worker pools.
No. MDN marks it Baseline Widely available (since about March 2022). It is not Deprecated, Experimental, or Non-standard.
Not necessarily. It reports logical processors (often higher than physical cores because of hyper-threading). The browser may also report a lower number that better matches how many Workers can run at once.
A common pattern is to create one Worker per logical processor (or slightly fewer, with a max cap) so heavy work can run in parallel without oversubscribing the CPU.
The property is Baseline, but a fallback like Math.max(1, navigator.hardwareConcurrency || 4) or a fixed default of 4 is a common defensive habit in older code.
No. It is read-only. You read the number; you cannot change the reported concurrency.
Did you know?
MDN’s example creates one Worker per reported logical processor and tracks an inUse flag — a tiny thread pool you can reuse for many jobs without spawning a new Worker every time.