musicman Posted May 14, 2016 Share Posted May 14, 2016 Hi, why the html5 checker required <img /> instead of <img></img> while both works..? Nu HTML Checker Link to comment Share on other sites More sharing options...
davej Posted May 14, 2016 Share Posted May 14, 2016 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"/> 1 Link to comment Share on other sites More sharing options...
dsonesuk Posted May 14, 2016 Share Posted May 14, 2016 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. 1 Link to comment Share on other sites More sharing options...
musicman Posted May 14, 2016 Author Share Posted May 14, 2016 Thanks guys! hr tag seems doesn't require closing at all (?) Link to comment Share on other sites More sharing options...
Ingolme Posted May 14, 2016 Share Posted May 14, 2016 Empty elements such as <br>, <hr>, <img>, <link> and so on do not require a closing tag or even a closing slash. Link to comment Share on other sites More sharing options...
dsonesuk Posted May 14, 2016 Share Posted May 14, 2016 HR void empty element, requires closing slash if page doctype is that of xhtml. Link to comment Share on other sites More sharing options...
musicman Posted May 14, 2016 Author Share Posted May 14, 2016 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) Link to comment Share on other sites More sharing options...
davej Posted May 14, 2016 Share Posted May 14, 2016 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now