Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

White space inside XML/HTML tags

Tags:

html

xml

tags

I know how white space is handled in text nodes for XML and HTML, but I'm uncertain about white spaces inside tag elements themselves. Obviously, white spaces are used inside tags to separate attributes, but is it valid to have white spaces after '<' or before '>'?

For example:

<  foo  > < /foo > 

Or even:

<foo> < /  foo > 

Are these tags valid XML? What about HTML, assuming they were actual HTML tag names?

like image 268
Channel72 Avatar asked Jul 23 '10 00:07

Channel72


People also ask

Is whitespace allowed in XML?

In XML documents, there are two types of whitespace: Significant whitespace is part of the document content and should be preserved. Insignificant whitespace is used when editing XML documents for readability. These whitespaces are typically not intended for inclusion in the delivery of the document.

How do you whitespace in XML?

As already mentioned the correct way to have a space in an XML file is by using \u0020 which is the unicode character for a space.

What is a whitespace in XML?

White space in XML is any character from the following set: space, tab and blank line/new line (except hard return). White space serves the following purposes: Visually format the document in its source form, such as for code, to denote semantic significance for the XML document.

Are spaces allowed in HTML tags?

@fakaff: Yes, that is valid. Line breaks, tabs and spaces are all white space characters, and you can have as much white space as you like after the tag name and between attributes (and even around the = in an attribute).


1 Answers

The specification (section 3.1 Start-tags, end-tags, and empty-element tags) says that there is no white space between the '<' and the tag name, between '</' and the tag name, or inside '/>'. You can add white space after the tag name, though:

<foo            > </foo        > <bar /> 
like image 123
Guffa Avatar answered Sep 18 '22 03:09

Guffa