3 ms·
The closing tags of HTML and XML are a nuisance. In SGML (their common predecessor), named closing tags were optional (you used </>), but were deliberately made
by 10ren 18y ago
The closing tags of HTML and XML are a nuisance. In SGML (their common predecessor), named closing tags were optional (you used </>), but were deliberately made mandatory in HTML and XML, to improve readability of long documents. It was contentious at the time, and it still is. But we must at least accept the data points that both HTML and XML have been phenomenally successful, without knowing for sure whether this particular feature was for or against.
One thing about dumb, regular, symmetrical formats is that their redundancy makes them less scary and easier to understand. Perhaps, this is accessibility is crucial for adoption.
EDIT I guess indentation enables you to match up start/end tags even better than named close tags... and it's certainly become more familiar to developers since Python's success. But maybe not so good when you have many levels of indentation, and terrible if you want to insert/delete a nested element, because the indentation of the elements within it must also be changed.
- ubernostrum 18y agoI think you'd be surprised at just what you're allowed to omit in HTML. For example, the following document is valid HTML 4.01 Strict: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <title></title> <p> The 'html', 'head' and 'body' elements -- opening and closing -- are inferred at the correct points by a compliant parser, as is the closing of the lone 'p' element. Once upon a time on my personal blog, I used minimal HTML 4.01 Strict (omitting tags and other bits of syntax whenever and wherever possible -- I had a Markdown fork that knew how to do this within the constraints of the spec); my one concession was a longer DOCTYPE declaration to deal with anything that didn't know how to resolve the public identifier. Browsers actually handled it just fine, but some other systems (in particular, OpenID autodiscovery) failed, because they weren't actually doing HTML parsing.
- 10ren 18y agoYou're right, I'd forgotten about omitting the closing </p>, but I think that's the only one (omitting a whole element - both open and close - is something different). Of course, in practice, most HTML parsers will do a wonderful job of interpreting malformed HTML.
- randallsquared 18y agoIt's not the only one. You can omit closing tags for td, tr, th, li, and probably others I don't remember. I actually do this; it doesn't make the resulting document any less clear for humans, and so if I'm typing it myself, there's little point in inserting them.
- donalm 18y agoThe main reason that SGML allowed closing tags to be optional was that it was 80s technology and storage was expensive. To omit tags you needed a DTD that allowed the parser to infer where the close tags should go. Enforcing the use of close tags in XML meant that building a parser was much simpler and that you no longer had to supply a DTD which I think were probably very instrumental in XML's success.