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.