📜 ⬆️ ⬇️

HTML Validation - Myth

The time has come and I will reveal the main secret:

There is nothing terrible if your site is unavailable due to 2-3 attributes that you yourself invented.

Try to think of a good reason why this statement is fundamentally wrong before read more.

Let's first imagine ourselves in the place of the microwave of the future. Let's say you, as a strict and inexpensive microwave, support the display only (!) XHTML. Most likely you will hardly validate each document before rendering, it will take extra processor time, and besides, you would need a DTD, the ability to validate it (just in case I remind you that a valid document is not just a well-formed). Rather, it would be cheaper for you to just try to display it. Nobody argues that an unclosed tag or incorrect nesting (the case is not well-formed) can seriously confuse the XHTML code parser, but really, if you find an invalid attribute (in the case of not valid XHTML), you clear the screen and show the housewife a mistake? Not. Because you will not find them. Because you do not need to detect them. You will search for only those attributes that you support, which you can display. Even if you will do a loop on all the attributes of the element, I am sure there is no point in processing the unknowns.
')
From the very beginning, the HTML and XHTML specification included a useful recommendation: when detecting an unknown attribute or element, it is recommended that the browser ignore it. Imagine, otherwise it would be impossible to ensure the forward compatibility and we would only sit on HTML 3.2.

  <input type = "text" required = "required" name = "creditcard" accept = "[0-9]" pattern = "[0-9] {13,16}" /> 
Yes, this is not valid XHTML, which automatically means that it is not XHTML at all. But this does not mean that it is not compatible with XHTML and that any XHTML browser cannot derive it using the principle of graceful degradation.

Think up your attributes and elements, create support in JavaScript for them, do not use class / rel / for to indicate the sign of a mandatory form field, it makes no sense to use comments like <! - BEGIN block1 -> to specify blocks. This creates problems for the same coder. Use required = "required". Use <block name = "block1">. Extend XHTML within your site only. Ensure compatibility with those who have javascript disabled. And no one will tell you anything bad.

There is no point in being an ideal browser that understands only Strict XHTML. It has not yet been created just because nobody needs it and this is not a W3C end in itself (although some people think so for some reason). After all, the basis of any competent specification (which distinguishes it from the “castle in the sand”) is not a desire for tightening, but the provision of flexibility, compatibility in both directions and competent thinking through graceful degradation. And all this has long been implemented in the framework of HTML and XHTML. Just start enjoying these thoughtful principles.

Source: https://habr.com/ru/post/9123/


All Articles