What’s the Difference between Tilde(~) and Caret(^) in package.json?

Better Stack Team
Updated on March 11, 2024

In a package.json file, the tilde (~) and caret (^) symbols are used to specify version ranges for your project’s dependencies. They help you control which versions of packages can your projects use when you run npm install or yarn install.

The tilde prefix (~) indicates that the tilde symbol will match the most recent patch version or the most recent minor version, i.e., the middle number. For example, ~1.2.3 will match all 1.2.x but not 1.3.x versions.

The caret prefix (^) indicates the first number, i.e., the most recent major version. It will update you on all future minor/patch versions without incrementing the major version. For example ^1.2.3, will use releases from 1.2.3 to <2.0.0

It is important to note that both ~ and ^ assume that you can trust minor and patch releases from your dependencies.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github