Minify Text
Minify text — collapse all whitespace into single spaces
Fast online whitespace minifier that removes extra spaces, tabs and blank lines to normalize whitespace, collapse multiple spaces and convert multiline text into a single line. Use this to compact HTML/CSS fragments, minify HTML or minify CSS snippets, clean exported text, or prepare single-line strings for storage or copying. Not for Markdown — this tool will break Markdown formatting.
How it works
- Replaces newline
\n, carriage return\rand tab\twith a single space. - Collapses any run of whitespace (
/\s+/g) into one space — effectively collapsing multiple spaces and normalizing whitespace. - Does not change characters or punctuation — it only normalizes and collapses whitespace.
How to use
- Paste your text or code into the editor.
- Choose Transform → Minify Text.
- Copy the single-line result.
Common use cases
- Text minifier for cleaning exported data and logs.
- Convert multiline HTML or CSS to a single-line string for embedding or quick copying — useful to minify HTML and minify CSS fragments.
- Minify string or minify txt when you need compact, single-line output.
- Normalize whitespace and collapse whitespace runs before storing or transmitting text.
Examples
Plain text — preview
Before:
This is a sentence.
It has multiple
line breaks and tabs.
After:
This is a sentence. It has multiple line breaks and tabs.
CSS — preview
Before:
.btn {
display: inline-block;
padding: 10px 20px;
color: #fff;
}
After:
.btn { display: inline-block; padding: 10px 20px; color: #fff; }
JavaScript — risky case (preview)
Before:
var a = 1
(function(){ console.log(a); })();
After (minified):
var a = 1 (function(){ console.log(a); })();
This can break runtime behavior because the immediately-invoked function expression becomes attached to the previous statement when there is no terminating semicolon. Always test JS after minifying and add semicolons where needed.
Tips & edge cases
Safe for many HTML and CSS snippets
Collapsing whitespace is usually acceptable in HTML and CSS; browsers ignore extra spaces and line breaks in most contexts. Use this tool when you want to minify HTML or minify CSS fragments for embedding or quick copying.
JavaScript can break without semicolons
Warning: this tool can break JavaScript that relies on automatic semicolon insertion. If a line starts with (, [, +, - or similar tokens, add an explicit semicolon on the previous line before minifying, or test the result thoroughly.
Not suitable when exact line breaks matter
Do not use this tool for content that requires preserved line breaks or formatting (poetry, diffs, formatted code examples). It converts line breaks to spaces and collapses spacing, so precise formatting will be lost.
If you need Markdown-safe cleanup
In case of Markdown, this tool will break formatting. To reduce whitespace in Markdown without breaking it, run Remove → Empty Lines and Remove → Trim first: Remove Empty Lines and Trim. These tools will reduce blank lines and trim edges while preserving Markdown structure.
Related tools
FAQ
Q: What exactly does this tool remove?
A: It replaces newlines (\n), carriage returns (\r) and tabs (\t) with spaces and then collapses any run of whitespace (/\s+/g) into a single space. It collapses multiple spaces and normalizes whitespace but does not remove punctuation or characters.
Q: Will this break my Markdown?
A: Yes — this tool will break Markdown formatting. Use Remove Empty Lines and Trim to reduce whitespace in Markdown safely.
Q: Is this safe for HTML and CSS?
A: Generally yes — the tool works as a whitespace minifier for HTML and CSS fragments and is useful to collapse whitespace for compact embedding or copying.
Q: Can it break JavaScript?
A: It can. If your JavaScript relies on automatic semicolon insertion, collapsing line breaks may change runtime semantics. Add semicolons or test after minifying.
Paste your text and run Minify Text to normalize whitespace, collapse multiple spaces and convert multiline content to a single line. Test any JavaScript after minifying to ensure behavior is unchanged.