Are self-closing tags valid in HTML5?

Problem:

You have an HTML page which contains non-void elements (which have contents with end tag). Suppose <div></div>, <p></p>. Now you don’t want to use end tag (</div>) and instead you like to use self-closing tags like this – <div />, <p />.
Is there any validity of this format in HTML5?

Solution:

No, it is not valid to use self-closing tags on non-void elements. If you use <div/>, it means <div>, the start tag, not <div></div>. Because non-void elements need contents. If you use <div/>, there is no option for entering contents.



Pin It

↑ Back to Top