Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Void Element and Self-Closing Tags

This is a total n00b question:

This seems very Square/Rectangle but, is it correct to say that a Void Element is a Self-Closing tag, but a Self-Closing tag is not always a Void Element?

<HR> and <BR> are both Void Elements and Self-Closing tags, but <META> and <DOCTYPE> are Self-Closing tags but not Void Elements?

Is this correct?

1 Answer

Void elements USE self-closing tags. Self-Closing tags are used for void elements.

It's a nuance but it's like this: A cat uses claws. A cat without claws is not a correct cat. Claws are only used on cats. Not true but sticking with the metaphor

A HTML image is a void element. A void element requires a self-closing tag by using:

<img... blah blah blah />

However, that being said, HTML5 doesn't require closing void elements, it's really a preference. If you're used to XHTML for example, you may as well keep the habit.