Can web pages be made future proof?

css, doctype, html, standards

Solution

I understand that `<!DOCTYPE html>` makes the browser render the page in standards mode, but that does not prevent your page from breaking when say, HTML 6 comes out.

Yes, it does. Additions to HTML are designed to be backwards compatible so that browsers don't start rendering older pages incorrectly.

Instead of making standards so generic, why don't they make it so that at the top of your page you explicitly specify the version of the standard you're targeting?

They tried that, although for different reasons (HTML was designed as an SGML application, but browsers didn't implement it as such). Every version of HTML and XHTML prior to HTML 5 did that. Browsers didn't distinguish between versions (only between quirks / almost standards / standards modes, all of which had far more impact on the handling of CSS and DOM then of HTML). Most authors didn't write code to match the Doctype they used.

What is a browser supposed to do if it sees a Doctype it doesn't recognise? It can either refuse to render the page (which doesn't help users at all) or it can try to render it as best it can (which is what it does).

What is a browser supposed to do if it sees a Doctype that doesn't support elements that are in the document? It can either ignore them (which doesn't help any one), throw an error (which could help a developer, but only if the developer tested in the most restrictive browser on the market, otherwise it just harms users), or render them as best it can (which is what it does).

The point of Doctype Switching and Quirks mode isn't to support web pages designed for older versions of HTML, but for pages designed for early, extremely buggy browsers.

Today, browsers are much better designed, much more rigorously tested, and their authors are much better about writing specifications for new HTML/CSS/DOM features, creating test suites for them and having multiple implementations of the feature (in different browsers) before they get public, unprefixed implementations that aren't locked behind a config option deep inside the browser. This dramatically reduces the number of things that are likely to break as browsers are updated, so there aren't significant new bugs that they need to remain backwards compatible with.

they know that this page has no idea about the HTML 6 standards, so to guarantee that the page will not break, the browser falls back to HTML 5 standards.

See above re backwards compatibility.

Problem

I understand that `<!DOCTYPE html>` makes the browser render the page in standards mode, but that does not prevent your page from breaking when say, HTML 6 comes out. Instead of making standards so generic, why don't they make it so that at the top of your page you explicitly specify the version of the standard you're targeting? Instead of `<!DOCTYPE html>`, do something like `<!DOCTYPE html=5>` so that when a future browser comes around with HTML 6, and they see the line `<!DOCTYPE html=5>` they know that this page has no idea about the HTML 6 standards, so to guarantee that the page will not break, the browser falls back to HTML 5 standards. This is like a backwards compatibility approach, so that a page you write today, is guaranteed to work for decades. Of course, you should not wait decades to update your pages, but at least you know it won't break the moment a new version of the standard comes out, and at the same time your page supports older browsers without changing one line of HTML. Why aren't things this way? What's wrong with that approach?

Original source