
The article focuses on such a seemingly cheated and expropriated topic as web document validation using one of the DTD schemes, which in turn are determined using the
DOCTYPE .
This topic is not trivial; the advantages and disadvantages of this or that validation method are not always obvious at first glance. Therefore, I decided that to mention them once again would not be superfluous.
Recently, many editors and CMS'ki automatically put a DOCTYPE for the document, which in itself is a breakthrough, but unfortunately this is not enough, since it is often the Transitional scheme. Beginner developers do not pay enough attention to this, and often do not even suspect that they have a choice.
')
Before proceeding to the very essence of the question, let us recall what the Transitional scheme is. It was created as a transition to facilitate the transition from HTML3.2 to HTML4, while preserving inherited elements and attributes.
Abstracting from a particular language, whether it is HTML or XHTML, the main drawback of Transitional is that the transitional validation scheme allows for the presence in the markup of elements responsible for a presentational visual display.
Modern web development is based on three pillars - markup (html / xhtml / xml), design (css) and functionality with effects (javascript). Moreover, the emphasis here falls on a clear separation between them. Markup is a logical division of the document into semantic, semantic components. The style rules made in a separate file (s) are responsible for the design of the document on display devices. The scripts responsible for the interaction between the document and the user, as well as for the effects, are also rendered into separate files. Mixing all of these components in one document is considered a move and significantly complicates the life of a web developer and decently increases the loading and display time of the document by the browser.
Unfortunately, we are all far from ideal and all the problems described above have always been present. But time does not stand still, markup languages ​​develop. Developers are moving forward with them, but the legacy should not be forgotten. Therefore, a transition scheme was invented, which allows us to validate a document containing a mess of elements, styles, attributes and scripts.
All this was done in the hope that conscious developers will move to a new standard, and then pull up their projects. But in this case, unfortunately, the expression “
nothing is more permanent than temporary ” fits very well.
And what exactly do you do?
Use Strict DTD - a strict, unambiguous scheme of document validation, which is designed to separate content from styles and scripts. How to do it? Very simple. In your next project, simply change the DOCTYPE to one of these:
<! DOCTYPE html PUBLIC "- // W3C // DTD HTML 4.01 // EN" "http://www.w3.org/TR/html4/strict.dtd">
<! DOCTYPE html PUBLIC "- // W3C // DTD XHTML 1.0 Strict // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
By the way, W3C definitely recommends using Strict.
“This is the HTML 4.01 Transitional DTD, which is Authors should use the Transitional DTD when it’s possible.
What do you lose by moving to a rigorous validation scheme:
List of prohibited items : applet, basefont, center, dir, font, iframe, isindex, menu, noframes, s, strike, u
List of prohibited attributes :
- Alink attribute denied for body
- The background attribute is not allowed for body
- The bgcolor attribute is not allowed for body, table, td, th, tr
- The border attribute is not allowed for img, object , but can be used in table
- The clear attribute is not allowed for br
- Language attribute denied for script
- Link attribute denied for body
- The name attribute is not allowed for form, img , but can be used in a, button, input, map, meta, object, param, select, textarea
- Noshade attribute is not allowed for hr
- The nowrap attribute is not allowed for td, th
- Start attribute denied for ol
- The target attribute is not allowed for a, area, base, form, link
- Text attribute is not allowed for body
- The type attribute is not allowed for li, ol, ul , but can be used in a, button, input, link, object, param, script, style
- The value attribute is not allowed for li , but can be used in button, input, option, param
- The vlink attribute is not allowed for body
Structural changes : elements
a, abbr, acronym, b, bdo, big, br, button, cite, code, dfn, em, i, img, input, kbd, label, map, object, q, samp, select, small, span, strong, sub, sup, textarea, tt, var and text cannot be children of
blockquote, body, form, noscript . In other words,
blockquote, body, form, noscript elements can have only block elements in the first-level child elements.
Refusal of the attribute
target = "_ blank" for links. First, telling the user how and where to open the link is not beautiful. Secondly, if necessary, this can be done in a
simple way and
advanced .
What do you gain?
- Well structured markup
- Clear separation of content from design
- The possibility of faster and easier work and support code
- Discipline writing code
- Respect and respect;)
When should I use Transitional? There are two main points. The transition scheme is good when you work with a large number of someone else's code, which is not possible to change. A good example is most CMS. In most cases, it is impossible to change their code without getting into the kernel, which automatically excludes the possibility of updates.
The second point is the use of an iframe. If you use iframe in your projects, it does not leave you a choice. Use Transitional.
In order to facilitate the transition from a transitional scheme to a strict document marking, think about what this or that element is for, and not about how it will look.