W3cubDocs

/Web APIs

Crypto: randomUUID() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨March 2022⁩.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Note: This feature is available in Web Workers.

The randomUUID() method of the Crypto interface is used to generate a v4 UUID using a cryptographically secure random number generator.

Syntax

randomUUID()

Parameters

None.

Return value

A string containing a randomly generated, 36 character long v4 UUID.

Examples

/* Assuming that self.crypto.randomUUID() is available */

let uuid = self.crypto.randomUUID();
console.log(uuid); // for example "36b8f84d-df4e-4d49-b662-bcde71a8764f"

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Opera Safari Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet WebView Android WebView on iOS
randomUUID 92 92 95 78 15.4 92 95 65 15.4 16.0 92 15.4

See also

© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID