Is it possible to have attribute values that span multiple lines?

Html

Html Problem Overview


e.g.

<div class="big
            left
            important"> some content </div>

Does anyone know if this breaks things / has good browser support?

Html Solutions


Solution 1 - Html

Returns, tabs, etc are considered white space and should be treated the same. I've seen and done formatting similar to how you have posted it. Some may discourage it. But I've never seen anything choke on it.

When creating my own web robots, I've had to clean up the white space in order for them to function because ultimately the robot runs into examples such as yours.

Solution 2 - Html

The class attribute is by HTML 4.01 specs of type:

> class = cdata-list [CS] > > This attribute assigns a class name or set of class names to an element. Any number of elements may be assigned the same class name or names. Multiple class names must be separated by white space characters.

That cdata-list references then to:

> CDATA is a sequence of characters from the document character set and may include character entities. User agents should interpret attribute values as follows:
> > - Replace character entities with characters, > - Ignore line feeds, > - Replace each carriage return or tab with a single space.

Taken all this into account then what you suggest in your question is perfectly OK with the specs. I know that browser-support is good for that.

More generally, whitespace incl. line feeds and carriage return are allowed in quoted attribute values since the first version of HTML. Browser support is very good for that.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjonView Question on Stackoverflow
Solution 1 - HtmlWayneView Answer on Stackoverflow
Solution 2 - HtmlhakreView Answer on Stackoverflow