Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


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.