A very common recommendation is not to put spaces around html-attributes. Actually, almost no one puts them.

And why did such a recommendation arise? Was there any browser that couldn't handle it? Or earlier it did not meet the standard?

Now the w3c validator says that the code with spaces is correct. Checked on such code:

<!DOCTYPE html> <title>Test</title> <p data-x = any> 

Here it is quite unreasonably stated that spaces will lead to an error.

Do not try to put spaces between the attribute name, equality and attribute value (this will lead to an error)! By the way, decent people write the attribute value in quotes. Although in most cases this is not necessary, I still recommend doing it.

But where will they lead to it? Apparently the article is quite ancient.

  • by contradiction: why put them and lower readability? - etki

1 answer 1

I think the only reason is that extra characters increase the size of the page, especially for large, heavy projects. No wonder that all scripts and styles are compressed by removing all spaces and line breaks.

  • But what about the recommendation to put quotes? These are the same two characters per value. In addition, there are minifiers. Here it is quite unreasonably stated that spaces will lead to an error. But where will they lead to it? Judging by the capital letters, the article is very old. - Qwertiy
  • Quotes are necessary in cases where the attribute value contains a space, for example. And the article is really rather dubious. - Plikard
  • Article there is average, but not dubious. Yes, if you look at it with the current level of html / css, then there is absolutely something wrong. But it looks like she is just older. This is the beginning of the development of html, when the tags were written in large letters, the doctype was not and css, perhaps, too. Find now the articles of the time is quite problematic. Even about IE Quirks 5 is hard to find, and this is even earlier. - Qwertiy