Is option a self-closing tag?

Is the option tag a self-closing tag?

Start tag: required , End tag: optional

That is for HTML 4, so one can assume it is still the case with HTML5. However, when the stricter XML compliance rules apply, it may not be the case.

HTML can be served as text/html or as application-x/xml, the latter adhering to the stricter spec.

Going through the HTML5 docs I’m still looking for clarification…

https://dev.w3.org/html5/pf-summary/forms.html#the-option-element

2 Likes

Hi, no expert here, but, if you don’t use the closing tag </option> here at codecademy the linter or whatever it is that puts a red dot on the code line number will show it’s not right. So most likely it’s not a self closing tag. Empty elements and void elements and self-closing are all three the same thing.

But it is when inside a <datalist/>. Linters don’t tell us if markup is valid, just if it has some quality issues.

validator.w3.org is where to get the real low down on our markup.

You are evidently much more knowledgeable about this area of computer technology than i am ok. But, I am not convinced <option>is a void or self closing tag just because in a few cases you don’t need the closing tag Link to the HTML5 specification of this tag. Maybe i am being a little too specific or narrow on this, but, a void or self closing tag like <br>and <img> never needs a closing tag and I think of them as a true void or self closing tag. Whereas <option> just acts like a void or self closing tag with regard to whether or not you or I need to put the closing tag in under specific circumstances. I would like to thank you for your answer as it has really helped me in sharpening my critical thinking skills with respect to learning the HTML5 computer language. I agree with you whole heartedly about W3C people being the ultimate authoritative source to go to though. They seem to be in charge of the actual development and evolution of the language itself to the best of my understanding.

1 Like

For me the question is “why”. Why is it not a self-closing tag?