Martti Laine
Martti Laine

Reputation: 12985

Correct way to leave empty elements in xhtml?

I've been experimenting with xhtml and now I'm wondering that is there a valid/correct way to add empty elements.

Short question, but here's the two ways I've been using:

<div> </div>
<div>&#32;</div> <!-- Same as space -->

Upvotes: 1

Views: 517

Answers (2)

carillonator
carillonator

Reputation: 4743

<div />

is valid XTHML for an empty element: i.e. self-closing. Same as

<div></div>

Upvotes: 0

nickf
nickf

Reputation: 546035

Like this:

<div></div>

A space inside an element is not "nothing" - it's a text node which makes the element non-empty.

Upvotes: 3

Related Questions