Spaces between html attributes and values?

ぐ巨炮叔叔 提交于 2019-11-27 03:23:07

问题


Are they allowed? and do they work with all browsers?

Example:

<div role = "region"
     id = "some-id"
     class = "a-class another-class">

回答1:


Yes, any amount of whitespace is allowed and will work in all browsers.

One consideration - this will add to the page size, so if bandwidth and performance are concerns, try to limit the amount of whitespace you use.




回答2:


Yes, it is perfectly valid markup. Whitespace is handled nicely by all browsers.

Any time you have confusion, you can validate your code at official W3 validation service:

  • http://validator.w3.org/



回答3:


Yes they are, and they will work in all major browsers, although I would say it should be considered bad practice to include unnecessary white-space as it pointlessly increases the size of the document.

HTML, XHTML, XML and others are all variants of SGML, so if you want to know what is/isn't allowed in general, have a look at that specification. You should always pass all your documents through the W3C markup validators to ensure they are valid.



来源:https://stackoverflow.com/questions/7064095/spaces-between-html-attributes-and-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!