Question

I was just wondering about a random misc. convention. If you for some reason have an empty div, would you do

<div></div>

or would you do

<div />
Was it helpful?

Solution

The latter is not valid markup, a div element cannot close itself like img or br

The reason is that a div is considered a non-void element. This means it is meant to have content, even if you leave it empty.

Here is a list of elements which can be void, or self closing

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top