Ian Storm Taylor
Ian Storm Taylor

Reputation: 8700

Spaces between html attributes and values?

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

Example:

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

Upvotes: 20

Views: 12687

Answers (3)

Oded
Oded

Reputation: 499132

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

From the Attributes section of the HTML5 living standard on unquoted, single-, and double-quoted attribute value syntax:

The attribute name, followed by zero or more ASCII whitespace, followed by a single U+003D EQUALS SIGN character, followed by zero or more ASCII whitespace, [...]

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.

Upvotes: 17

DaveRandom
DaveRandom

Reputation: 88697

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.

Upvotes: 6

Sarfraz
Sarfraz

Reputation: 382806

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:

Upvotes: 4

Related Questions