Skip to content
FLAVIO COPES
flaviocopes.com
2026

Generating UUIDs in JavaScript with window.crypto.randomUUID()

~~~

If you’ve ever needed to generate unique identifiers in your web applications, window.crypto.randomUUID() is a method that generates a v4 UUID (Universally Unique Identifier).

It’s part of the Web Crypto API and is supported in all modern browsers.

Why Use It?

  1. Simplicity: No need for external libraries or complex algorithms.
  2. Security: It uses a cryptographically strong random number generator.
  3. Standards-compliant: Generates UUIDs according to RFC 4122.

Here’s how to use it:

const uuid = window.crypto.randomUUID();
console.log(uuid); // e.g. "36b8f84d-df4e-4d49-b662-bcde71a8764f"
~~~

Related posts about platform: