On this page
Overview
js-cookie is a lightweight JavaScript library that wraps client-side cookie operations in Cookies.set, get, and remove. It applies RFC 6265-compatible encoding and accepts attributes such as expiry, path, domain, secure, and sameSite as an object.
Features and best fit
Based on official documentation; not hands-on tested · Content checked:
Key features
Create, read, and remove cookies through one API
Cookies.set() writes a value and its attributes, Cookies.get() reads cookies visible to the current page, and Cookies.remove() deletes them. The library has no dependencies.
Sources: [1]
Declare expiry, path, domain, secure, and sameSite attributes
Per-cookie attributes are passed to Cookies.set(), while withAttributes() creates an API instance with shared defaults for repeated use.
Sources: [1]
Best fit
Fits browser interfaces that need a small explicit cookie state layer
It is useful for preferences, consent state, and other short browser-visible values when a frontend wants one consistent API instead of hand-building document.cookie strings.
Sources: [1]
Before adoption
Deletion must repeat the attributes used when the cookie was created
When a cookie uses non-default path, domain, secure, or sameSite values, Cookies.remove() must receive the same values or the cookie will remain.
Sources: [1]
Read visibility is determined by the current browser context
Passing domain or path attributes to Cookies.get() does not change its search scope. A cookie is returned only when browser cookie rules make it visible from the current page.
Sources: [1]
Official sources
- [1]js-cookie 3.0.8 README(2026-10-05)
- [2]js-cookie 3.0.8 package metadata(2026-10-05)
- [3]js-cookie 3.0.8 release(2026-10-05)
- [4]js-cookie security policy(2026-10-05)
- [5]js-cookie MIT license(2026-10-05)
Supplemental curator note
js-cookie is practical when a browser application wants to avoid hand-building document.cookie strings while keeping cookie attributes explicit. Pay particular attention to deletion: non-default path, domain, secure, and sameSite attributes must match the values used when the cookie was created.
Try it in 3 steps
- 1
Install js-cookie 3.0.8 in an isolated project
Pin the current release and inspect its browser distribution without changing an existing project.
demo=$(mktemp -d "${TMPDIR:-/tmp}/js-cookie.XXXXXX") && cd "$demo" && npm init -y >/dev/null && npm install --save-exact js-cookie@3.0.8 - 2
Create minimal HTML that sets, reads, and removes a cookie
Load the UMD build and exercise the documented set/get/remove flow while repeating the same sameSite attribute for removal.
printf "%s\n" '<!doctype html>' '<meta charset="utf-8">' '<script src="./node_modules/js-cookie/dist/js.cookie.js"></script>' '<script>' "Cookies.set('oss-tanbou-demo', 'ok', { sameSite: 'strict' });" "document.body.textContent = Cookies.get('oss-tanbou-demo');" "Cookies.remove('oss-tanbou-demo', { sameSite: 'strict' });" '</script>' > index.html - 3
Open the HTML in a browser and verify the value
Open
index.htmlin a browser and confirm the page showsok; the script removes the demo cookie afterward.index.html
Growth
Growth trends · Last 30 days
22,573 Stars
Trend data is still being collected.
Development activity
Last 90 days · weekly
- Commits (last 30 days)
- 1
- Open PRs
- 7
Development activity is still being collected.
Built with
Categories and tags
Categories
GitHub data
GitHub dataView detailed GitHub data
GitHub Topics
- cookie
- javascript
- Stars
- 22,573
- Forks
- 2,042
- Watchers
- 329
- Open issues
- 3
- Contributors
- 56
- Owner type
- Organization
- Primary language
- JavaScript
- License
- MIT
- Repository last updated
- Sep 17, 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
- 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 - Electron123,388 Stars
3 shared tag(s) · 1 shared category(s)
bundle Chromium and Node.js to build desktop applications for three major operating systems with HTML, CSS, and JavaScript
C++
Report incorrect information
Tell us if any listing information is incorrect or outdated.