<p>I've noticed a lot of sites, SO included, use XHTML as their mark-up language and then fail to adhere to the spec. Just browsing the source for SO there are missing closing tags for paragraphs, invalid elements, etc.</p>

<p>So should tools (and developers) use the XHTML doctype if they are going to produce invalid mark up? And should browsers be more firm in their acceptance of poor mark-up?</p>

<p>And before anyone shouts hypocrite, my blog has one piece of invalid mark-up involving the captha (or it did the last time I checked) which involves styling the noscript tag.</p>

[{'answer_id': 3453, 'author': 'Michael Stum', 'author_id': 91, 'author_profile': 'https://Stackoverflow.com/users/91', 'pm_score': 0, 'selected': False, 'text': '<p>It depends. I had that <a href="http://www.stum.de/2008/02/29/valid-xhtml-and-youtube-embedding/" rel="nofollow noreferrer">issue with my blog</a> where a YouTube video caused invalid XHTML, but it rendered fine. On the other hand, I have a "Valid XHTML" link, and a combination of a "Valid XHTML" claim and invalid XHTML is not professional.</p>\n\n<p>As SO does not claim to be valid, I think it\'s acceptable, but personally if I were Jeff i would be bothered and try to fix it even if it looks good in modern browsers, but some people rather just move on and actually get things done instead of fixing non-existent bugs.</p>\n'}, {'answer_id': 3457, 'author': 'Bryan Denny', 'author_id': 396, 'author_profile': 'https://Stackoverflow.com/users/396', 'pm_score': 0, 'selected': False, 'text': "<p>So long as it works in IE, FF, Safari, (insert other browser here) you should be okay.  Validation isn't as important as having it render correctly in multiple browsers.  Just because it is valid, doesn't mean it'll work in IE properly, for instance.</p>\n\n<p>Run Google Analytics or similar on your site and see what kind of browsers your users are using and then judge which browsers you need to support the most and worry about the less important ones when you have the spare time to do so.</p>\n"}, {'answer_id': 3460, 'author': 'Lauren', 'author_id': 265, 'author_profile': 'https://Stackoverflow.com/users/265', 'pm_score': 1, 'selected': False, 'text': "<p>I wouldn't use XHTML at all just to save myself the philosophical stress. It's not like any browsers are treating it like XHTML anyway.</p>\n\n<p>Browsers will reject poor mark-up if the page is sent as application/xhtml+xml, but they rarely are. This is fine.</p>\n\n<p>I would be more concerned about things like inline use of CSS and JavaScript with Stack Overflow, just because they make maintenance harder.</p>\n"}, {'answer_id': 3461, 'author': 'Grant', 'author_id': 30, 'author_profile': 'https://Stackoverflow.com/users/30', 'pm_score': 0, 'selected': False, 'text': "<p>I say, if it renders OK, then it doesn't matter if it's pixel perfect. </p>\n\n<p>It takes a while to get a site up and running the way you want it, going back and making changes is going to change the way the page renders slightly, then you have to fix <em>those</em> problems.</p>\n\n<p>Now, I'm not saying you should built sloppy web pages, but I see no reason to fix what ain't broke. Browsers aren't going to drop support for error correction anytime in the near future.</p>\n"}, {'answer_id': 3462, 'author': 'UnkwnTech', 'author_id': 115, 'author_profile': 'https://Stackoverflow.com/users/115', 'pm_score': 0, 'selected': False, 'text': "<p>I don't understand why everyone get caught up trying to make their websites fit the standard when some browsers sill have problems properly rendering standard code.  I've been in web design for something like 10 years and I stopped double codding (read: hacking css), and changing stupid stuff just so I could put a button on my site.</p>\n\n<p>I believe that using a &lt; div> will cause you to be invalid regardless, and it get a bit harder to do any major JavaScript/AJAX without it.</p>\n"}, {'answer_id': 3465, 'author': 'Teifion', 'author_id': 1384652, 'author_profile': 'https://Stackoverflow.com/users/1384652', 'pm_score': 0, 'selected': False, 'text': '<p>There are so many standards and they are so badly "enforced" or supported that I don\'t think it matters. Don\'t get me wrong, I think there should be standards but because they are not enforced, nobody follows them and it\'s a massive downward spiral.</p>\n'}, {'answer_id': 3468, 'author': 'Tom', 'author_id': 20, 'author_profile': 'https://Stackoverflow.com/users/20', 'pm_score': 1, 'selected': False, 'text': '<p>Though I believe in striving for valid XHTML and CSS, it\'s often hard to do for a number of reasons.</p>\n\n<ul>\n<li>First, some of the content could be loaded via AJAX. Sometimes, fragments are not properly inserted into the existing DOM.</li>\n<li>The HTML that you are viewing may not have all been produced in the same document. For example, the page could be made of up components, or templates, and then thrown together right before the browser renders it. This isn\'t an excuse, but you can\'t assume that the HTML you\'re seeing was hand coded all at once.</li>\n<li>What if some of the code generated by Markdown is invalid? You can\'t blame Stack Overflow for not producing valid code.</li>\n<li>Lastly, the purpose of the DOCTYPE is not to simply say "Hey, I\'m using valid code" but it\'s also to give the browser a heads up what you\'re trying to do so that it can at least come close to correctly parsing that information.</li>\n</ul>\n\n<p>I don\'t think that most developers specify a DOCTYPE and then explicitly fail to adhere to it.</p>\n'}, {'answer_id': 3471, 'author': 'Greg Hurlman', 'author_id': 35, 'author_profile': 'https://Stackoverflow.com/users/35', 'pm_score': 0, 'selected': False, 'text': "<p>For 99.999% of the sites out there, it really won't matter.  The only time I've had it matter, I ran the HTML input through HTMLTidy to XHTML-ize it, and then ran my processing on it.</p>\n\n<p>Pretty much, it's the old programmer's axiom: trust no input.</p>\n"}, {'answer_id': 3479, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>while I agree with the sentiment of "if it renders fine then don\'t worry about it" statement, however it\'s good for follow a standard, even though it may not be fully supported right now. you can still use Table for layout, but it\'s not good for a reason.</p>\n'}, {'answer_id': 3492, 'author': 'John Siracusa', 'author_id': 164, 'author_profile': 'https://Stackoverflow.com/users/164', 'pm_score': 5, 'selected': True, 'text': '<p>There are <a href="https://validator.w3.org/docs/why.html" rel="nofollow noreferrer">many reasons</a> to use valid markup.  My favorite is that it allows you to use validation as a form of regression testing, preventing the markup equivalent of &quot;delta rot&quot; from leading to real rendering problems once the errors reach some critical mass.  And really, it\'s just plain sloppy to allow &quot;lazy&quot; errors like typos and mis-nested/unclosed tags to accumulate.  Valid markup is one way to identify <a href="https://web.archive.org/web/20100913081355/http://stackoverflow.com:80/questions/3247/identifying-passionate-programmers" rel="nofollow noreferrer">passionate programmers</a>.</p>\n<p>There\'s also the issue of debugging: valid markup also gives you a stable baseline from which to work on the inevitable cross-browser compatibility woes.  No web developer who values his time should begin debugging browser compatibility problems without first ensuring that the markup is at least <em>syntactically</em> valid—and any other invalid markup should have a good reason for being there.</p>\n<p>(Incidentally, stackoverflow.com fails both these tests, and suggestions to fix the problems <a href="http://stackoverflow.uservoice.com/pages/general/suggestions/14739" rel="nofollow noreferrer">were</a> <a href="http://stackoverflow.uservoice.com/pages/general/suggestions/14740" rel="nofollow noreferrer">declined</a>.)</p>\n<p>All of that said, to answer your specific question, it\'s probably not worthwhile to use one of the XHTML doctypes unless you plan to produce valid (or at <em>least</em> well-formed) markup.  XHTML\'s primary advantages are derived from the fact that XHTML is XML, allowing it to be processed and transformed by tools and technologies that work with XML.  If you don\'t plan to make your XHTML well-formed XML, then there\'s little point in choosing that doctype.  The latest HTML 4 spec will probably do everything you need, and it\'s much more forgiving.</p>\n'}, {'answer_id': 39137, 'author': 'LeoD', 'author_id': 2868, 'author_profile': 'https://Stackoverflow.com/users/2868', 'pm_score': 2, 'selected': False, 'text': "<p>We should always try to make it validate according to standards. We'll be sure that the website will display and work fine on current browsers AND future browsers.</p>\n"}, {'answer_id': 39160, 'author': 'Kamiel Wanrooij', 'author_id': 4174, 'author_profile': 'https://Stackoverflow.com/users/4174', 'pm_score': 2, 'selected': False, 'text': "<p>I don't think that, if you specify a doctype, there is any reason not to adhere to this doctype.</p>\n\n<p>Using XHTML makes automated error detection easy, every change can be automatically checked for invalid markup. This prevents errors, especially when using automatically generated content. It is really easy for a web developer using a templating engine (JSP, ASP.NET StringTemplate, etcetera) to copy/paste one closing tag too little or too many. When this is your only error, it can be detected and fixed immediately. I once worked for a site that had 165 validation errors per page, of which 2 or 3 were actual bugs. These were hard to find in the clutter of other errors. Automatic validation would have prevented these errors at the source.</p>\n\n<p>Needless to say, choosing a standard and sticking to it can never benefit interoperability with other systems (screen scrapers, screen readers, search engines) and I have never come across a situation where a valid semantic XHTML with CSS solution wasn't possible for all major browsers.</p>\n\n<p>Obviously, when working with complex systems, it's not always possible to stick to your doctype, but this is mostly a result of improper communication between the different teams developing different parts of these systems, or, most likely, legacy systems. In the last case it's probably better to isolate these cases and change your doctype accordingly.</p>\n\n<p>It's good to be pragmatic and not adhere to XHTML just because someone said so, regardless of costs, but with current knowledge about CSS and browsers, testing and validation tools, most of the time the benefits are much greater than the costs.</p>\n"}, {'answer_id': 63999, 'author': 'dawnerd', 'author_id': 69503, 'author_profile': 'https://Stackoverflow.com/users/69503', 'pm_score': 2, 'selected': False, 'text': "<p>You can say that I have an OCD on XHTML validity. I find that most of the problems with the code not being valid comes from programmers not knowing the difference between HTML and XHTML. I've been writing 100% valid XHTML and CSS or a while now and have never had any major rendering problems with other browsers. If you keep everything valid, and don't try anything too exotic css wise, you will save yourself a ton of time in fixes.</p>\n"}, {'answer_id': 194061, 'author': 'Kornel', 'author_id': 27009, 'author_profile': 'https://Stackoverflow.com/users/27009', 'pm_score': 1, 'selected': False, 'text': '<p>No, you should not use XHTML if you can\'t guarantee well-formedness, and in practice you can\'t guarantee it if you don\'t use XML serializer to generate markup. Read <a href="http://hsivonen.iki.fi/producing-xml/" rel="nofollow noreferrer">about producing XML</a>.</p>\n\n<p>Well-formedness is <em>the</em> thing that differentiates XHTML from HTML. XHTML with "just one" markup error ceases to be XHTML. <em>It has to be perfect every time</em>.</p>\n\n<p>If "XHTML" site appears to work with some errors, it\'s because <a href="http://www.xml.com/pub/a/2003/03/19/dive-into-xml.html" rel="nofollow noreferrer">browsers ignore the DOCTYPE</a> and interpret page as HTML.</p>\n\n<p>See <a href="http://schneegans.de/xp/" rel="nofollow noreferrer">XHTML proxy</a> that forces interpretation of pages as XHTML. Most of the time <a href="http://schneegans.de/xp/?url=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F3448%2Facceptable-for-invalid-xhtml&amp;ct=application%2Fxml" rel="nofollow noreferrer">they fail miserably</a>. This is one of the reason why future of XHTML is uncertain and <a href="http://dig.csail.mit.edu/breadcrumbs/node/166" rel="nofollow noreferrer">why development of HTML has been resumed</a>.</p>\n'}]
['https://Stackoverflow.com/questions/3448', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/342/']