question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remove all white spaces between any tags

See original GitHub issue

I have complete control over my HTML code and I really need to remove all spaces between all type of elements: block level and inline level — now white spaces collapses only between block level elements.

Is there a way to remove all spaces between all tags completely?

(I’m using grunt-contrib-htmlmin v0.3.0 Grunt plugin which is a wrapper of HTML minifier)

I’ve found similar issues like #273, but I still got spaces between <button> or <span> tags.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
Njkecommented, May 15, 2015

Btw, here is a quick fix, using gulp-replace (just add this after .pipe(htmlmin(...))):

.pipe(replace(/>\s+</g, '><'))
0reactions
sapicscommented, Nov 20, 2015

Following, white-spaces around inline tag might remove, isn’t it? (need to add new options like removeInlineTagWhitespace)

// https://github.com/kangax/html-minifier/blob/gh-pages/src/htmlminifier.js#L59
-      || (prevTag.substr(0, 1) === '/' && tags.indexOf(prevTag.substr(1)) === -1))) {
+      || (prevTag.substr(0, 1) === '/' && (options.removeInlineTagWhitespace || tags.indexOf(prevTag.substr(1)) === -1)))) {

// https://github.com/kangax/html-minifier/blob/gh-pages/src/htmlminifier.js#L64
-      || (nextTag.substr(0, 1) !== '/' && tags.indexOf(nextTag) === -1))) {
+      || (nextTag.substr(0, 1) !== '/' && (options.removeInlineTagWhitespace || tags.indexOf(nextTag) === -1)))) {
Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove white spaces between tags in HTML - php
You need use a regular expresion. Maybe you can use this: $html = preg_replace('/\>\s+\</m', '><', $html);. Test here https://repl.it/.
Read more >
Remove Whitespace in Html with Javascript - Jake Trent
Here's some javascript to strip out the whitespace between xml/html tags. I'm no regex guru, so I split this into 4 separate pieces:...
Read more >
How to remove the white space between elements - YouTube
4 elements with a width of 25% and a display of inline-block, should all appear on the same line. However, that's not always...
Read more >
Remove All White Space Between Tags - TeX
Ideally it would be across many lines as shown in the first example, because this will eventually be a long string generated by...
Read more >
How to remove the space between inline-block elements?
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found