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]
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.
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]Nano ID 6.0.1 README(2026-10-05)
- [2]Nano ID 6.0.1 package metadata(2026-10-05)
- [3]Nano ID changelog(2026-10-05)
- [4]Nano ID 6.0.1 release(2026-10-05)
- [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
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
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
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
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
Related information
Write a related articleShare a guide or use case for this OSS in Markdown. Articles are published after administrator approval.
Explore next
- Autoprefixer22,211 Stars
3 shared tag(s) · 1 shared category(s) · Same language
generate only the vendor prefixes required by Browserslist and Can I Use data
JavaScript - Less17,025 Stars
3 shared tag(s) · 1 shared category(s) · Same language
compile stylesheets with variables, mixins, and nesting into standard CSS with lessc
JavaScript - Stylelint11,526 Stars
3 shared tag(s) · 1 shared category(s) · Same language
continuously check CSS errors and conventions with 100+ rules, plugins, and shareable configs
JavaScript - Stylus11,333 Stars
3 shared tag(s) · 1 shared category(s) · Same language
use indented syntax or regular CSS style with one expressive stylesheet compiler
JavaScript - i18next8,637 Stars
3 shared tag(s) · 1 shared category(s) · Same language
keep translation keys, plurals, interpolation, and resource loading independent of the UI framework
JavaScript - Bootstrap174,991 Stars
3 shared tag(s) · 1 shared category(s)
Build responsive interfaces from a CSS/Sass grid, utilities, components, and native JavaScript
MDX
Report incorrect information
Tell us if any listing information is incorrect or outdated.