![]() A guide should be objective, and you can be objective when you follow the minimum requirement. The fact that you can be subjective it’s another story. Like mrf explained, in a style guide there shouldn’t be any subjective choice in order to create. Though HTML allows one to use or not use closing tags for empty elements, the idea is not about what you are allowed to do but what is the minimum requirement in order for one to do what he wants. However, I would like to comment on this debate. I’m actually studying HTML as a total beginner. That is my value judgement and it is no more, nor no less, subjective than yours. Using them is one less thing I have to think about when I’m bouncing between documents and languages in a project, which allows me to better focus on larger problems. To me, those are the most important facts to consider, therefore the best practice is to use self-closing tags. ![]() I say that self-closing tags are valid HTML, were folded into the HTML5 spec from the XHTML spec, and that using them maintains consistency with every other tag in an HTML document, and maintains consistency with other markup languages web devs are likely to encounter, namely XML and JSX, which require self-closing tags. You’ve made a value judgement about what you think is most important to consider in this decision. ![]() ![]() If I’m reading you correctly, you think that those are the most important facts to be considered, therefore the best practice is to omit self-closing tags unless otherwise required. You say that self-closing tags are unnecessary for text/html docs and are not part of the HTML 4.1 spec from which the HTML5 spec is mostly derived. And if both options are equally valid, then the choice as to which one we use is inherently subjective. The spec treats both options as equally valid. But it’s perfectly valid to include it if you want to. So, by all means, omit the slash if that’s your preference. I understand that not everyone shares my phobia, though. It bugs me to see sporadic unclosed tags throughout a document full of otherwise closed tags. Personally, I prefer all of my tags to close. So according to the W3C,, , and are all valid HTML. In both HTML and XHTML, within each tag, whitespace is permitted after the tag name…Some authors choose to include a space before the slash in the self-closing tag. These indicate that the element is to be closed immediately, and has no content. The self-closing tag syntax may be used.Ī Self-closing tag is a special form of start tag with a slash immediately before the closing right angle bracket. In HTML, these elements have a start tag only. Just so that it’s 100% clear for everyone, the W3C HTML5 spec explicitly states that either syntax is fine. Closing these tags will not impress anybody. The HTML 4 standard should be applied across the board and closing void tags set aside when not explicitly required. ![]() Generally speaking, a production site that serves XML conforming HTML5 will have its server configured to send that MIME type in the header of pages served out so that no declaration is needed in the document.Īs for best practices, subjectivity should be avoided, as it tends to introduce bias. HTML5 came along at a time when browser quirks were being ironed out and that allowed it to remove the space before the slash that was needed in XHTML. That means all void elements must be closed. It is when we explicitly serve the document with an XML MIME type, then HTML5 is equivalent to XHTML which must conform to XML syntax. Under this MIME type the browser never parses XML so there is no need to close void elements. HTML5 is essentially HTML 4.1 when served with the default MIME type, text/html. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |