OSS TanbouSign in with GitHub

generate short URL-safe IDs from cryptographic randomness and tune the alphabet and length for each use case

About these scores

OSS scale score is an unbounded metric that log-compresses and weights Stars, Watchers, Forks, and Contributors. Discovery score is the current OSS scale score minus the score at discovery. Update pace is commits in the last 30 days, growth momentum is the OSS scale score difference within the recent observation window, and OSS health is a 0–100 rating based on available recency, Community Health, and release data.

Stars
27,076
Primary language
JavaScript
License
MIT
Repository last updated
Oct 5, 2026
On this page

Overview

Nano ID is a JavaScript library that uses Node.js crypto and the Web Crypto API to generate compact URL-safe random IDs. Its default generator packs roughly 126 bits of randomness into 21 characters and can be customized with a different alphabet or length.

Features and best fit

Based on official documentation; not hands-on tested · Content checked:

Key features

Generate 21-character URL-safe IDs from cryptographic randomness

The default nanoid() uses the A-Za-z0-9_- alphabet and returns 21 characters. It relies on Node.js crypto or the browser Web Crypto API rather than Math.random().

Sources: [1]

Control the alphabet and length with customAlphabet

customAlphabet() defines both the character set and default size, while callers can override the size. Shorter IDs increase collision probability, so the documentation links to a collision calculator for sizing decisions.

Sources: [1]

Use the same generator from ESM, browsers, and the CLI

The npm package is ESM and exposes a browser entry. The documented npx nanoid CLI can generate IDs with optional --size and --alphabet arguments.

Sources: [1][2]

Best fit

Fits client and server code that needs random identifiers shorter than UUID text

It works well for URLs, UI records, and application identifiers that need compact random values without a centrally assigned sequence.

Sources: [1]

Before adoption

Version 6.0.1 targets Node.js 22, 24, or 26 and later lines

Package metadata requires ^22 || ^24 || >=26 and declares the package as ESM. Older Node.js or CommonJS-oriented environments should verify compatibility before adopting it.

Sources: [2][3]

Do not generate React keys on every render

The README says that calling nanoid() for React key props is incorrect because keys must remain stable across renders. It recommends stable data IDs and React useId for label/input relationships.

Sources: [1]

Official sources

  1. [1]Nano ID 6.0.1 README(2026-10-05)
  2. [2]Nano ID 6.0.1 package metadata(2026-10-05)
  3. [3]Nano ID changelog(2026-10-05)
  4. [4]Nano ID 6.0.1 release(2026-10-05)
  5. [5]Nano ID MIT license(2026-10-05)
Supplemental curator note

Nano ID is useful when a project needs compact random IDs while retaining explicit control over alphabet and length. Version 6.0.1 targets Node.js 22, 24, or 26+ lines, and the README explicitly warns against generating React keys on each render.

Try it in 3 steps

  1. 1

    Install Nano ID 6.0.1 in an isolated project

    On a supported Node.js 22, 24, or 26+ line, pin the reviewed release without modifying an existing project.

    demo=$(mktemp -d "${TMPDIR:-/tmp}/nanoid.XXXXXX") && cd "$demo" && npm init -y >/dev/null && npm install --save-exact nanoid@6.0.1
  2. 2

    Create a script for default and custom-alphabet IDs

    Generate the default 21-character URL-safe ID and a 10-character hexadecimal ID from the same package.

    printf "%s\n" "import { nanoid, customAlphabet } from 'nanoid';" "const id = nanoid();" "const hexId = customAlphabet('0123456789abcdef', 10)();" "console.log({ id, hexId });" "if (id.length !== 21 || hexId.length !== 10) throw new Error('unexpected Nano ID length');" > demo.mjs
  3. 3

    Run the script and verify both lengths

    Confirm the default cryptographic ID is 21 characters and the customAlphabet result is 10 characters.

    node demo.mjs
Check the official README

Growth

Growth trends · Last 30 days

27,076 Stars

Trend data is still being collected.

Development activity

Last 90 days · weekly

Commits (last 30 days)
10
Open PRs
4

Development activity is still being collected.

Built with

Categories and tags

Categories

GitHub data

GitHub dataView detailed GitHub data
Stars
27,076
Forks
889
Watchers
162
Open issues
1
Contributors
143
Owner type
User
Primary language
JavaScript
License
MIT
Repository last updated
Oct 5, 2026
Write a related article

Share a guide or use case for this OSS in Markdown. Articles are published after administrator approval.

Report incorrect information

Tell us if any listing information is incorrect or outdated.

After reading this page, do you know what to do next?