Nano ID Generator

Generates compact, URL-safe unique IDs in the style of the popular Nano ID library, using the Web Crypto API with a configurable length and a fully customizable character alphabet. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-25

Overview

Introduction

Nano ID is a widely used alternative to UUID for generating unique, URL-friendly string IDs in web applications.

This tool reproduces its default format and behavior client-side, using cryptographically secure randomness, with full control over length and the character alphabet.

What Is Nano ID Generator?

A compact random ID generator using a 64-character URL-safe alphabet by default (uppercase and lowercase letters, digits, underscore, and hyphen), with a default length of 21 characters.

Both the length and the alphabet are fully customizable, letting you match this tool's output to whatever ID format your application expects.

How Nano ID Generator Works

The tool fills a typed array with cryptographically random 32-bit values via crypto.getRandomValues(), then maps each value onto your chosen alphabet by modulo, deduplicating repeated characters in a custom alphabet first.

Everything runs synchronously in the browser with no network request involved.

When To Use Nano ID Generator

Use it wherever you'd use a UUID but want a shorter, URL-safe string — API resource IDs, short links, client-generated component keys.

Customize the alphabet when your system has character restrictions, such as case-insensitive storage or a filesystem that disallows certain symbols.

Features

Advantages

  • Shorter than a UUID while offering comparable collision resistance at the default length.
  • URL-safe by default, with no characters that need percent-encoding.
  • Fully customizable alphabet and length for matching existing ID formats.

Limitations

  • This is a format-compatible implementation, not an import of the original nanoid package, so it won't be byte-for-byte identical to output from that library given the same random seed (nanoid doesn't support seeding anyway).
  • Very short lengths combined with small custom alphabets can meaningfully increase collision risk — check the odds for your specific length and alphabet size.

Examples

A default 21-character ID

Input

(no input; generated from settings)

Output

V1StGXR8_Z5jdHi6B-myT

Drawn from the default 64-character URL-safe alphabet.

Best Practices & Notes

Best Practices

  • Stick with the default 21-character length unless you have a specific reason to shorten or lengthen it — it's a well-reasoned default balancing size against collision resistance.
  • Keep the default alphabet unless your system has a specific character restriction, since it's already fully URL-safe.
  • Generate a batch when seeding test fixtures rather than calling the tool repeatedly for one ID at a time.

Developer Notes

Alphabet deduplication runs via Array.from(new Set(...)) before generation, so a custom alphabet like 'aabbcc' behaves identically to 'abc' — this avoids silently skewing the distribution toward duplicated characters.

Nano ID Generator Use Cases

  • Generating IDs for client-side React/Vue component keys
  • Creating short, URL-safe resource identifiers for an API
  • Producing session or request IDs for logging

Common Mistakes

  • Assuming this generator is deterministic or seedable — like the original nanoid, it always produces fresh cryptographically random output.
  • Using an alphabet with fewer than a handful of unique characters, which inflates collision probability dramatically at any practical length.

Tips

  • For case-insensitive systems, restrict the alphabet to lowercase letters and digits to avoid subtle bugs from case-folding collisions.
  • Generate a batch at once when seeding test fixtures rather than running the tool repeatedly.

References

Frequently Asked Questions