UUID v4 Generator — Free HTML CSS JS Snippet

UUID v4 Generator · Forms · Plain HTML, CSS & JS · Live preview

What's included

Features

Generates UUIDs with crypto.getRandomValues, never Math.random
Correct RFC-4122 version 4 and variant bit-setting on the raw bytes
Single large UUID display with its own copy button
Batch mode generates 10 UUIDs at once, each independently copyable
Standard 8-4-4-4-12 hyphenated formatting
Clipboard copy via navigator.clipboard.writeText with button feedback
Scrollable batch list for generating larger sets without layout breakage
Zero dependencies — pure Web Crypto and DOM APIs

About this UI Snippet

UUID v4 Generator — Cryptographically Random RFC-4122 UUIDs

Screenshot of the UUID v4 Generator snippet rendered live

This snippet generates version 4 UUIDs that follow the RFC-4122 specification exactly, sourcing every random bit from crypto.getRandomValues rather than Math.random, which is not suitable for identifiers that must avoid collisions or be unpredictable.

Correct bit-setting

After filling a 16-byte Uint8Array with secure random values, the function overwrites the top nibble of byte 6 to 0100 to mark the UUID as version 4, and the top two bits of byte 8 to 10 to mark the RFC-4122 variant — exactly as the spec requires, so the output is a spec-compliant v4 UUID rather than just a random-looking string.

Formatting

Each byte is converted to its two-character hex representation and the 16 hex pairs are joined into the standard 8-4-4-4-12 UUID layout with hyphens inserted at the correct positions.

Single and batch generation

The main panel shows one large UUID with its own copy button, refreshed by "Generate new UUID". The "Generate 10" button produces a scrollable list of ten fresh UUIDs, each with an individual copy button built dynamically with document.createElement.

Build with AI

Build, Understand, Optimize, and Extend It With AI

Hand this snippet's HTML, CSS, and JavaScript to an AI coding assistant like Claude and ask it to adapt "UUID v4 Generator" to your project — restyle it to match your design system, wire it up to real data instead of the static example, or port it to the framework you're building in.

Prompt to recreate it

Copy this into your AI assistant of choice to build the effect from scratch, or as a jumping-off point for your own variant:

text
Build a forms component called "UUID v4 Generator" using plain HTML, CSS, and vanilla JavaScript — no framework, no build step.

Requirements:
- Match the structure and behavior of the "UUID v4 Generator" snippet from the UI Snippets Library.
- Keep the markup semantic and the styling self-contained (no external dependencies beyond what the original snippet uses).
- Keep the JavaScript vanilla, with no framework runtime required.
- Make it easy to restyle via CSS custom properties or class overrides so it can be dropped into a real project.

Want to tighten it up first? Run this prompt through the AI Prompt Studio to score it across 8 quality dimensions, catch anti-patterns, and tune the wording for Claude, ChatGPT, or Gemini before you paste it in.

Source Code

<div class="uvg-card">
  <div class="uvg-head">
    <h2>UUID v4 Generator</h2>
    <p>RFC-4122 version 4 UUIDs generated with a cryptographically secure random source.</p>
  </div>

  <div class="uvg-main-row">
    <code id="uvgMainUuid">…</code>
    <button class="uvg-copy" id="uvgMainCopy" type="button">Copy</button>
  </div>

  <div class="uvg-actions">
    <button class="uvg-btn uvg-btn-primary" id="uvgGenOne" type="button">Generate new UUID</button>
    <button class="uvg-btn" id="uvgGenTen" type="button">Generate 10</button>
  </div>

  <ul class="uvg-batch" id="uvgBatch"></ul>
</div>

Step by step

How to Use

  1. 1
    Load the snippetClick "UUID v4 Generator" in the sidebar to load its HTML, CSS, and JS into the editor panels. The preview updates instantly.
  2. 2
    Edit the codeModify any panel — HTML, CSS, or JS. The preview refreshes as you type. Use Reset in each panel header to restore the original.
  3. 3
    Preview on devicesClick the Mobile (375px), Tablet (768px), or Desktop buttons in the preview header to check responsiveness.
  4. 4
    Export in your formatClick "HTML" to download a standalone file, "JSX" for a React component, "Tailwind" for a React + Tailwind CSS component, "Tailwind HTML" for a standalone HTML file with Tailwind CDN, "Vue" for a Vue 3 SFC with <template>/<script setup>/<style scoped>, or "Angular" for a standalone Angular .component.ts file. "Copy all" copies the full code to clipboard.
  5. 5
    Save your versionClick "Save as", type a name, and press Enter. Your snippet saves to IndexedDB and appears in the Saved tab.

Real-world uses

Common Use Cases

Database seeding tools
Quickly generate primary key UUIDs for test or seed data.
API testing utilities
Produce unique request or resource identifiers for manual API testing.
Developer utility sites
Offer a standalone UUID generator alongside other dev tools.
RFC-4122 teaching example
Shows exactly how version and variant bits are set in a v4 UUID.

Got questions?

Frequently Asked Questions

Math.random is not guaranteed to be cryptographically secure and can be predictable, which is unsuitable for identifiers meant to be globally unique and non-guessable; crypto.getRandomValues uses the operating system's secure random source.

The generator explicitly sets the four version bits in byte 6 to 0100 and the two variant bits in byte 8 to 10, exactly as RFC-4122 requires, rather than relying on the raw random bytes to happen to look right.

With 122 random bits of entropy, the probability of two v4 UUIDs colliding is astronomically small even across billions of generated values.