Skip to content
Aback Tools Logo

LZ-String Text Compressor

Compress text using LZ77/LZ-String online for free — ideal for localStorage, cookies, and URL state. Choose from Base64, UTF-16 (localStorage-optimised), or URI Component output. Runs entirely in your browser, so your text never leaves your device. No signup required.

LZ-String Text Compressor
Compress or decompress text using LZ77/LZ-String — ideal for localStorage, cookies, and URL state. Choose Base64, UTF-16, or URI Component output. Runs entirely in your browser.

Best for general use, JSON storage, and API payloads. URL-safe with padding.

Why Use Our LZ-String Text Compressor?

Instant LZ-String Compression

Our lz-string text compressor processes your text instantly in the browser — no server round-trips, no wait time. Compress JSON, localStorage data, URL state, and any string to Base64, UTF-16, or URI Component output within milliseconds.

Secure LZ-String Compressor Online

Your text never leaves your device. Our lz-string compressor online runs entirely client-side in JavaScript — no data is ever sent to any server. Safely compress sensitive JSON payloads, user data, or configuration strings without any privacy risk.

LZ-String Compressor Online — No Installation

Use our lz-string text compressor directly in any modern browser — Chrome, Firefox, Safari, or Edge. No npm install, no Node.js, no plugins required. Works on desktop and mobile with zero setup.

100% Free Forever

Use our lz-string compressor completely free with no hidden costs, no signup, no ads, and no usage limits. Compress and decompress text online as many times as you need — for personal projects, professional work, or enterprise use. Free forever.

Common Use Cases for LZ-String Text Compressor

localStorage Compression

Compress large JSON objects before storing them in localStorage to stay within the 5–10 MB browser storage limit. Our lz-string text compressor using UTF-16 output is specifically optimised for localStorage — it stores 15 bits per character for maximum density.

URL State Compression

Compress application state into URL query parameters using URI Component output. Our lz-string compressor online produces URL-safe strings with no padding, perfect for shareable links that encode complex filter states, editor content, or configuration.

Cookie Data Compression

Compress cookie value strings to fit within the 4096-byte cookie size limit. Use our lz-string text compressor to reduce large session data, preferences, or tracking payloads before writing them to cookies.

Client-Side Caching

Compress API responses before caching them in IndexedDB, sessionStorage, or in-memory caches. Our lz-string compressor reduces JSON payload sizes by 40–70%, allowing you to cache significantly more data client-side.

Embedded Data in HTML

Compress large JSON datasets embedded in HTML pages as inline script data. Use our lz-string text compressor to reduce the size of data islands in server-rendered pages, improving initial page load time.

Offline-First App Storage

Compress structured data for offline-first Progressive Web Apps (PWAs) that need to store large datasets locally. Our lz-string compressor online helps you maximise the amount of data stored within browser storage quotas.

Understanding LZ-String Text Compression

What is LZ-String Compression?

LZ-String is a JavaScript text compression library based on the LZ77 algorithm (Lempel-Ziv 1977), which finds and replaces repeated substrings with back-references to earlier occurrences. Unlike GZIP, which is designed for file compression, lz-string compression is specifically optimised for compressing text strings in JavaScript environments — particularly for storing compressed data in localStorage, cookies, and URL parameters. Our free lz-string text compressor online implements the full LZ-String algorithm in pure TypeScript, running entirely in your browser with no external dependencies or server uploads.

How Our LZ-String Text Compressor Works

  1. Paste or Upload Your Text:Enter your text directly in the input panel, or click "Upload file" to load a .txt, .json, .csv, or any text-based file. Our lz-string compressor online accepts any string input.
  2. Choose Format and Mode: Select your output format (Base64, UTF-16, or URI Component) and whether to compress or decompress. All processing happens locally in your browser — your text never leaves your device.
  3. Copy or Download Output:Click "Compress Text" and the result appears instantly in the output panel. Copy it to clipboard with one click, or download it as a .txt file for use in your application.

Output Format Comparison

  • Base64: Encodes 6 bits per character using the standard Base64 alphabet. Best for general use, JSON storage, API payloads, and any context where ASCII-safe output is needed. Includes padding characters (=).
  • UTF-16: Encodes 15 bits per character using the full Unicode range. Produces the smallest output for localStorage — JavaScript strings are stored as UTF-16 internally, so this format maximises storage density.
  • URI Component: Encodes 6 bits per character using a URL-safe alphabet (no padding). Ideal for query parameters, hash fragments, and shareable URLs where the compressed string must be URL-safe.
  • Decompression: Select the same format used during compression and switch to Decompress mode to restore the original text. The format must match exactly — Base64-compressed text cannot be decompressed with the UTF-16 decoder.

When LZ-String Compression Is Most Effective

LZ-string compression works best on text with repetitive patterns — JSON objects with repeated keys, HTML with repeated tags, CSV with repeated values, and configuration objects with similar structures. Typical compression ratios are 40–70% for structured JSON and 50–80% for HTML. Very short strings (under ~50 characters) or already-compressed data (Base64-encoded images, encrypted strings) may not compress well — the LZ-String overhead can make the output larger than the input for minimal-repetition text. This is expected behavior.

Frequently Asked Questions About LZ-String Text Compressor

A LZ-String text compressor is a tool that compresses text strings using the LZ77 algorithm, producing a compact encoded output suitable for localStorage, cookies, and URL parameters. Our free lz-string text compressor online runs entirely in your browser — no server upload, no installation required.

No. LZ-String is a lossless compression algorithm — decompressing the output with the same format will restore your original text byte-for-byte with zero data loss. The compression only affects the encoded representation, never the underlying content.

Absolutely. Our lz-string text compressor processes everything locally in your browser using pure JavaScript. Your text is never uploaded to any server, never stored remotely, and never leaves your device. All compression and decompression happens entirely on your machine.

Yes — 100% free, forever. No signup, no account, no premium tier, no usage limits, and no ads. Compress and decompress text online as many times as you need for any purpose.

Use UTF-16 format for localStorage. JavaScript stores strings as UTF-16 internally, so the UTF-16 output format encodes 15 bits per character — significantly more dense than Base64 (6 bits per character). This means UTF-16 output is typically 40% smaller than Base64 output for the same input, maximising the amount of data you can store within the 5–10 MB localStorage limit.

Use URI Component format for URL query parameters and hash fragments. This format uses a URL-safe alphabet with no padding characters, so the output can be used directly in URLs without additional encoding. It produces the same compression ratio as Base64 but is safe for use in query strings.

Install the lz-string npm package (`npm install lz-string`) and use the matching decompress function: `LZString.decompressFromBase64()`, `LZString.decompressFromUTF16()`, or `LZString.decompressFromEncodedURIComponent()`. The format must match what was used during compression. Our tool uses the same algorithm as the official lz-string library.

LZ-String compression works by finding repeated patterns in text. Very short strings (under ~50 characters), random data, or already-compressed content (Base64-encoded images, encrypted strings) have few repetitions, so the LZ-String overhead makes the output larger. This is expected behavior — lz-string compression is most effective on structured, repetitive text like JSON objects with repeated keys.

No. LZ-String uses the LZ77 algorithm without Huffman coding, making it faster and simpler than GZIP (which uses LZ77 + Huffman). GZIP typically achieves better compression ratios for large files, but LZ-String is specifically designed for JavaScript string environments — it produces output that can be stored directly in localStorage, cookies, and URLs without binary encoding overhead.