When take some tutorial from web, I see many people leaves tags open like <link ..>, <img ..>. But when I use Netbeans to edit them (the HTML/JSP pages), it show a red background on those tags until I add the slash into them. <br> –> <br/>.
Which is the correct way to write HTML-based code?
Both are fine for HTML. Though not for XHTML which is an XML dialect.
Some elements do not need a closing (
/>) tag – in particular empty elements (those that do not have content). Examples are<hr>and<br>. These can also be self closing (<hr />and<br />, respectively). This self closing is equivalent to having a close tag immediately after the open tag.For XML, such a non closing tag is not valid – it must be closed, either self closing or have a closing tag. So
<hr>is not valid XML, but<hr />and<hr></hr>are.HTML is not XML, but for better compatibility some tools try to emit as much XML like HTML as possible.