Jump to content

Recommended Posts

Because some tags (such as <input/> and <img/> and <br/> and <hr/>) are singular tags and have no legal closing tags. Browsers are designed to be forgiving and they try to make sense of illegal syntax, however HTML validators are designed to be precise and unforgiving.

<button id="btn1">Press Here</button>

<input type="button" id="btn2" value="Press Here"/>
  • Like 1

Share this post


Link to post
Share on other sites

It may work, but it not truly valid, <img> is for html and the end slash <img /> is required for xhtml, closing tags </div> are for those elements that can hold content and other elements within them. Those elements such as hr, br that are not capable of holding content of any kind are known as void elements.

  • Like 1

Share this post


Link to post
Share on other sites

Empty elements such as <br>, <hr>, <img>, <link> and so on do not require a closing tag or even a closing slash.

Share this post


Link to post
Share on other sites

hmm, then this case is a bit weird.

 

on my app, WePro, I'm using an iframe to show snippets html files. When the snippet html files use <br>, I got error message and the html file won't show on the iframe. It says: "mismatched tag. Expected: </br>". (Mozilla)

 

 

Share this post


Link to post
Share on other sites

I believe the closing slash at the end of singular tags has always been optional but it was required in XHTML.

 

In HTML5 it is clearly stated that this slash is optional, but in HTML5 a lot of stuff is optional -- to such an extent that most code-writers refuse to produce the horrible-looking stuff that HTML5 will accept as perfectly legal.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...