Generate UUID in JavaScript

The simplest way to generate a UUID in JavaScript is to use the built in function crypto.randomUUID(). Note that this function is only available when your page is served from localhost or via https


var uuid = crypto.randomUUID();
console.log("Generated UUID: " + uuid);

If you need to generate a specific UUID version, you need to use a third-party library such as uuid which offers more flexible options:



import { v1, v3, v4, v5, v6, v7 } from 'uuid';

console.log("UUID version 1: " + v1());
console.log("UUID version 3: " + v3(name, v4());
console.log("UUID version 4: " + v4());
console.log("UUID version 5: " + v5(name, v4());
console.log("UUID version 6: " + v6());
console.log("UUID version 7: " + v7());

The Online UUID Generator on this site was implemented using this library, so another way to see it in action is to open it and view the page source.

How do I generate UUID in...

Find out how to generate UUIDs in your favorite language here: Bash, Groovy, Kotlin, Python, Scala, Clojure, ClojureScript, Java, or return to Online UUID Generator