Semver Comparator

Compare two semantic version numbers or sort a list of versions. Supports pre-release identifiers (alpha, beta, rc) and build metadata per the semver 2.0 spec.

1.0.0-alpha

<

A is older

1.0.0

Breakdown

PartVersion AVersion BDiff
Major11=
Minor00=
Patch00=
Pre-releasealphaB newer

About Semantic Versioning

Semantic Versioning (semver) is a versioning scheme defined at semver.org that encodes meaning into version numbers. A semver version has the format MAJOR.MINOR.PATCH: increment MAJOR for breaking changes, MINOR for backwards-compatible new features, and PATCH for backwards-compatible bug fixes. This convention allows package managers like npm, Cargo, and Composer to automatically determine whether updating a dependency is safe.

Pre-release versions (e.g., 1.0.0-alpha.1, 2.0.0-rc.3) have lower precedence than the release they precede — 1.0.0-alpha < 1.0.0. Pre-release identifiers are compared left-to-right: numeric identifiers compare numerically, alphanumeric identifiers compare lexicographically, and numeric identifiers always have lower precedence than alphanumeric. Build metadata (+build.123) is ignored in comparisons. The v prefix is stripped automatically.

All comparison logic runs locally in your browser implementing the semver 2.0.0 specification. The sort tool handles any number of versions and correctly orders pre-release identifiers, including the tricky case where 1.0.0-alpha.2 < 1.0.0-alpha.10 (numeric comparison, not lexicographic).

Frequently Asked Questions

Why is 1.0.0-alpha less than 1.0.0?

Per the semver spec, a pre-release version has lower precedence than the associated normal version. The reasoning: a pre-release version is unstable and not yet intended for production use — so it logically "comes before" the stable release. 1.0.0-alpha < 1.0.0-beta < 1.0.0-rc.1 < 1.0.0.

How are pre-release identifiers compared?

Identifiers are compared left-to-right. Purely numeric identifiers compare by numeric value (alpha.2 < alpha.10). Mixed or alphabetic identifiers compare lexicographically. Numeric identifiers always have lower precedence than alphanumeric ones (so 1.0.0-1 < 1.0.0-alpha). A longer pre-release string has higher precedence if all shorter identifiers are equal.

What does build metadata do?

Build metadata (e.g., 1.0.0+build.20240301) is informational and is ignored when determining version precedence. Two versions that differ only in build metadata are considered equal. It is typically used for CI build numbers or git commit hashes.

When should I increment major vs minor vs patch?

Patch (1.0.X): bug fixes that don't change the public API. Minor (1.X.0): new features that are backwards-compatible — existing users don't need to change their code. Major (X.0.0): breaking changes — removing or renaming public APIs, changing method signatures in incompatible ways. If you're unsure, increment major to be safe.