How to tell when an element is a void element?

Hello everyone,
I have a quick question. I am working to learn CSS with the help of everyone here, but I keep finding myself getting confused about when to (or not to) add a closing tag.

Are there any tricks you all have learned for remembering what elements are void elements?

It’s not the end of the world to get it wrong in practice, but I’m attempting to be a more well-rounded programmer and feel that to a certain degree some memorization will be necessary.

2 Likes

i think it just takes practice.
Use an online html validator like this one:

when you keep fixing the same mistake over and over, you’ll learn.

2 Likes

One way to think about it is this: if an element cannot contain child elements or some kind of content, whether it be code, styling or text, it is self closing. At least, that is how I think of it.

But @hbar1st is correct - you will have them memorized with a bit of practice. I do and I made no effort to memorize them. So don’t worry too much about it.

2 Likes

Hello @kmiller624 !

You are doing great!

Here is a link that may help to understand the self-closing elements in html, such as img, link, meta to name only a few. There is a list of common self-closing (also called void) elements in the information, as well.

Wishing you more good progress on your coding journey. :slightly_smiling_face:

1 Like

Thank you for the tips; I appreciate all the guidance!

2 Likes