UUID in JavaScript

JavaScript UUID Generator

JavaScript has shipped UUID v4 in the platform since 2021, so a random identifier is one method call away — crypto.randomUUID().

Built into the browserNo dependencyv4 + v7

Generated locally with the Web Crypto API — nothing leaves your browser.

Generating UUIDs in JavaScript

How to generate

  1. Press Generate UUID above to mint a value in this browser — nothing is sent anywhere.
  2. Copy one value with Copy, or set How many and use Copy all for a fixture list.
  3. Switch Version if your code needs v7 instead of the v4 default, and turn on Formatting to match your stack's conventions.

Use Cases

How JavaScript UUID Generator Compares

crypto.randomUUID()Built in, v4 only, CSPRNG-backed
uuid (npm)All versions including v7, ~3 kB
nanoidShorter and alphabet-configurable, not a UUID

Code Examples

JavaScript
// Browser and Node 19+
const id = crypto.randomUUID();
// 'f81d4fae-7dec-41d0-a765-00a0c91e6bf6'

// A batch, for fixtures
const ids = Array.from({ length: 25 }, () => crypto.randomUUID());
Older runtimes
// Node 16+/14.17, and for a v7 fallback
const { randomUUID, v7: uuidv7 } = require('crypto');
const { v7 } = require('uuid'); // npm install uuid

const v4 = randomUUID();
const timeOrdered = v7();

Frequently Asked Questions

Is crypto.randomUUID() available in every browser?
Yes in every current browser (Chrome 92+, Firefox 95+, Safari 15.4+) and in Node 19+. On older runtimes the uuid package is the drop-in replacement.
Does crypto.randomUUID() generate version 4?
Always. The version and variant nibbles are fixed by the spec, and there is no built-in v7 — that needs the uuid package or another generator.
How do I get a UUID without hyphens in JavaScript?
crypto.randomUUID().replaceAll('-', '') gives the 32-character hex form. Switch Hyphens off above to produce the same shape from this page.

Related tools