The full syntax of the html language. html syntax and html document structure

DOM as part of the language

The concept of DOM was first introduced in HTML5. (although it existed before that, however, it was not part of the language), the HTML document is now treated as a set of objects, not tags. Therefore, how HTML5 syntax does not exist. However, when writing code, you can stick to tag markup rules, which were set in HTML 4.01 or XHTML 1.0

HTML 4.01 syntax

AT HTML before the fifth version, there were several rules for writing code:

  1. The loose mode used in HTML 4.01
    "http://www.w3.org/TR/html4/loose.dtd">
  2. The strict mode used in HTML 4.01
    "http://www.w3.org/TR/html4/strict.dtd">
  3. There was also syntax associated with frames. Frames are considered obsolete in HTML5, but many developers still use them because frames are very useful when developing some web applications.

XHTML 1.0 Syntax

AT XHTML, there were two rules for writing code:

  1. The transitional mode used in XHTML 1.0
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. The strict mode used in XHTML 1.0
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Modern HTML5 Syntax

When using HTML5, writing at the beginning of the HTML document, doctype, you can use any of the language syntaxes listed above (code rules) or even mix HTML 4.01 and XHTML 1.0 together.

For example, don't quote attribute values ​​attribute=value (HTML 4.01 loose mode - loose), but at the same time put a slash in single tags
(XHTML 1.0 strict mode - strict).

XHTML (strict), most preferred

Experienced HTML coders usually use the strict XHTML strict syntax when writing HTML5 code, because it keeps the coder in good shape, does not allow him to relax, and thereby protects him from possible errors in code. Also, the use of strict syntax is useful when learning programming, because there the strictness of the syntax is extremely important.

HTML5 syntax

As you have already learned, some of the rules have been relaxed in HTML5. This was done because the creators of HTML5 wanted the language to more closely reflect how web browsers actually work. In other words, they wanted to bridge the gap between "working web pages" and "standard-correct web pages." In the next section, we'll look at the rule changes in more detail.

Of course, there are still obsolete browser-supported methods that are absolutely frowned upon by the HTML5 standard. These methods can be detected using the HTML5 validator.

Relaxed rules

In our first introduction to HTML5 markup, we learned that using elements , and is optional for this markup. But the relaxation of the rules in HTML5 doesn't stop there.

It also allows both uppercase and lowercase letters in tags, as in the following example:

In tags can be used both uppercase and lowercase letters.

It is also possible to omit the closing backslash in empty elements, i.e. elements with no content, such as (image),
(line break) or


(horizontal line). The following are three equivalent ways to insert a line break:

Example
gap
lines

HTML5 has also changed the rules for attributes. Attribute values ​​no longer need to be quoted, but only if they do not contain forbidden characters (usually >, =, or space). Here is an example using the element thus:

Attributes without values ​​are also allowed. Thus, if checking a checkbox in XHTML requires somewhat repetitive syntax:

then in HTML5 this can be done in the tradition of HTML 4.01, specifying only one attribute name:

But it's not that all of this is allowed in HTML5 that worries some, but that not-so-conscientious developers can casually use both strict and relaxed rules, sometimes even in the same document. But in fact, such sloppy markup is possible in XHTML as well. In both standards, good markup style is the responsibility of the web developer. the browser eats everything that is served to it.

    Using elements , and . In element it is convenient to place the definition of the natural language of the page, and the elements and allow you to separate information about the page from the actual content of the page.

    Lowercase letters in tags. The use of lowercase letters in tags is optional, but such tags are much more common and easier to type (because there is no need to press the key ), and also not as annoying as uppercase tags.

    Quoting attribute values. Attribute values ​​are quoted because there is a reason for this - to help avoid errors that in otherwise very easy to admit. Without quotes, one wrong attribute value character can ruin the entire page.

HTML5 code validation

The new relaxed approach to rules in HTML5 may be to the liking of some web developers. For others, the very idea that behind the façade of a browser that runs smoothly, without a hitch, there may be inconsistent, error-ridden markup, can deprive you of sleep.

If you're of the latter type, be aware that a markup validation tool called a validator can detect code that doesn't conform to the recommended HTML5 standards, even if the browser doesn't bat an eye while processing the code.

Some of possible problems that the validator is able to capture include the following:

    the absence of required elements (for example, the element );</p> <p>no closing tag;</p> <p>incorrectly embedded tags;</p> <p>the absence of attributes for tags for which they are required (for example, the src attribute of the tag <img>);</p> <p>incorrect positioning of elements or content (for example, text in a block <head>).</p> </ul><p>Web design tools such as Dreamweaver and <a href="https://zhumor.ru/en/internet/spravka-k-expression-web-4-na-russkom.html">Expression Web</a>, are equipped with their own validators, but only the most <a href="https://zhumor.ru/en/internet/doktor-veb-ne-daet-ustanovit-flesh-pleer-ustanovit-adobe-flash.html">latest versions</a> support HTML5. In this case, you can use one of the online validators. The following are instructions for using the popular W3C validator:</p> <p>Your code will be submitted for review, and after a short wait, a report will be displayed in the browser with the validation results. If the code did not pass the test, then the report will indicate the errors detected by the validator:</p> <p><img src='https://i0.wp.com/professorweb.ru/my/html/html5/level1/files/img46003.jpg' width="100%" loading=lazy loading=lazy></p> <p>Even for a perfectly valid HTML document, the report may show several warnings (albeit completely innocuous), including those that the encoding was determined automatically and the HTML5 code validation service is experimental and not quite taken to its logical end.</p> <p>As you can see in the figure, the validator detected four violations of the HTML5 rules in the document, resulting from two bugs in the code. First error - missing required element <title>. The second is an element<р>closes before its nested element closes <i>. However, despite these errors, this markup is correct and all browsers will display this page properly.</p> <h2>The return of XHTML</h2> <p>As we have already learned, the rise of the HTML5 specification marks, in theory, the decline of the previous king of the World Wide Web - the XHTML standard. But the reality is not so simple, and XHTML aficionados don't have to give up anything they love about previous generation markup languages.</p> <p>First of all, remember that the XHTML syntax continues to exist. The XHTML-imposed rules either continue to be used as guidelines (for example, rules for properly nesting elements) or are maintained as optional conventions (for example, the trailing slash convention with empty elements).</p> <p>But what if you want to make following the rules of XHTML syntax mandatory? Perhaps you're worried that you (or your co-workers) will unknowingly slip into the loose conventions of regular HTML. To prevent this you need to use <b>XHTML5</b>, is a less common standard that is essentially HTML5 wrapped in XML-based restrictions.</p> <p>To make an HTML5 document an XHTML document, you must explicitly specify the XHTML namespace on the element <html>, close each element, make sure to use lowercase letters in tags, and so on. The following listing provides an example code that fulfills all of these requirements:</p> <p> <!DOCTYPE HTML> <html lang="ru" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8"> <title>Tiny HTML5 Document

    Let's shake up the browser in HTML5 style!

    AT XHTML tags capital letters cannot be used.

    This code requires an XHTML validator to enforce the strict old XHTML rules. The validator from the W3C won't work for this, but the validator at http://validator.nu will do, where you need to specify the required standard (ie XHTML) in the Preset drop-down list. You also need to check the Be lax about HTTP Content-Type box, unless you're pasting the code you're checking directly into the text box.

    By following these steps, you will be able to create an XHTML document and validate it. However, browsers will still treat this document as a normal HTML5 page that just puffs up to look like an XML document. They will not apply any additional rules when processing such a page.

    If you also want browsers to process the page according to XHTML rules, then you need to configure your web server to serve pages with the application/xhtml+xml or application/xml MIME type, instead of the standard text/html type. By the way, browsers that support XHTML5 handle this markup differently than normal HTML5 code. They are trying to render the page like XML document, and if they fail (due to a bug in the code), the browser stops processing the rest of the document.

    What follows from this? For the vast majority of web developers, from hobbyists to serious professionals, playing by the strict rules of XHTML is not worth the candle required. The only exception is the development of custom solutions, such as pages with content that needs to be manipulated using XML tools such as XQuery and XPath.

    If you're wondering, it's possible to trick the browser into switching to XHTML mode. To do this, you just need to rename the file with the xhtml or xht extension, and then open it with hard drive your computer. Most browsers (including Firefox, Chrome, and IE 9) will treat such a page as if it were loaded from a web server with MIME XML settings. If the page contains any minor error, the browser will display a partially rendered page (IE 9), an XML error message (Firefox), or both (Chrome).

    HTML tags is the basis of the HTML language. Tags are used to delimit the start and end of elements in markup.

    Every HTML document consists of a tree of HTML elements and text. Each HTML element is identified by a start (opening) and an end (closing) tag. The start and end tags contain the tag name.

    All HTML elements are divided into five types:

    • empty elements , ,
      , , ,
      , , , , , , , , , ;
    • plain text elements
      Internet