Semantic Version Comparator

Compare semantic versions correctly, including prerelease precedence, and sort a list into real version order.

9Versions

Everything you type here is processed on your own device. No input is sent to a server, logged, or stored.

What the Semantic Version Comparator does

Use this semantic version comparator to compare semantic versions correctly, including prerelease precedence, and sort a list into real version order. Paste your text in, pick the options you need, and copy the result straight back out. It is most often used for working out which of two versions is newer. More utilities in this area are collected on FreeToolStation.org.

How to use it

  1. Paste one version per line. A leading v is accepted.
  2. Read the sorted order and which versions are prereleases.
  3. Check the span to see what kind of change the range implies.

How it works

Sorting versions as strings gives the wrong answer, and this is the most common version-handling bug. Lexically, "1.10.0" sorts before "1.2.0" because the character 1 comes before 2. Numerically it is later. Any system that sorts version strings alphabetically will eventually pick the wrong release.

Prerelease precedence has its own rules, laid out in the semver specification. A version with a prerelease tag always ranks below the same version without one, so 1.0.0-rc.1 comes before 1.0.0. Within prerelease identifiers, numeric parts compare numerically, alphanumeric parts compare as ASCII strings, and numeric always ranks below alphanumeric. That gives the familiar alpha, beta, rc ordering by accident of the alphabet rather than by design.

Build metadata after a plus sign is explicitly ignored in precedence. 1.0.0+build.1 and 1.0.0+build.99 are the same version as far as ordering is concerned, which is why build metadata should never be used to distinguish releases.

The major version zero rule is worth remembering: anything 0.x.y is explicitly outside the stability guarantee, and a 0.x minor bump may break everything. Caret ranges in npm treat ^0.2.3 as 0.2.x rather than 0.x for exactly this reason.

When to use it

  • Working out which of two versions is newer.
  • Sorting a list of release tags correctly.
  • Checking prerelease ordering before publishing.
  • Validating that version strings are well-formed semver.

Common mistakes to avoid

  • Sorting versions as strings, which puts 1.10.0 before 1.2.0.
  • Assuming a prerelease ranks above the release it precedes. It ranks below.
  • Using build metadata to distinguish versions. It is ignored in precedence.

Frequently asked questions

Is 1.10.0 newer than 1.2.0?

Yes. Numerically 10 is greater than 2. Sorting as strings gets this wrong, which is the most common version-handling bug.

Does 1.0.0-rc.1 come before or after 1.0.0?

Before. A prerelease always ranks below the same version without a prerelease tag.

Does build metadata affect version ordering?

No. Anything after a plus sign is explicitly ignored for precedence, so 1.0.0+build.1 and 1.0.0+build.99 are the same version.

Related tools

See all developer tools →