DOCTYPE. Why and how is it designed? HTML and XHTML Standards


Tagis responsible for the document type in HTML (DTD "document type definition", description of the document type). To be more precise, these are instructions for the browser what type of document is presented below.

Arises logical question: is html really different? The fact is that new tags appeared in different versions of html. New properties also appeared in CSS. In order for the browser to correctly understand which standard the page complies with, it is recommended to clearly indicate the document type in .

Locatedat the very beginning of the html code (before the tag ).

Syntax

Element top level ] [Publicity ] "[Registration ]//[Organization ]//[Type ] [Name ]//[Language ]" ""> ...
  • Top level element- top-level element in the document (for HTML this is a tag )
  • Publicity - the value is PUBLIC (the object is public) or SYSTEM ( system resource). For example, such as local file. For HTML/XHTML the value is PUBLIC.
  • Registration - takes one of two values: plus (+) - the developer is registered with ISO and minus (-) - the developer is not registered. For W3C the value is set to minus.
  • Organization - The unique name of the organization that developed the DTD. Officially HTML/XHTML is published by the W3C, and this is the name written in .
  • Type - the type of the document being described (for HTML/XHTML, the DTD value).
  • Name - a unique document name to describe the DTD.
  • Language is the language in which the text is written to describe the object. Contains two letters, written in uppercase. For example, EN.
  • URL - the address of the document with the DTD.

Let's look at which standard values ​​are most common.

Table with valuesand descriptions for them

DOCTYPE Description
Strict HTML syntax
Transitional HTML syntax
HTML document uses frames
HTML5 standard. For all documents. It is recommended to use it on your websites.
Strict XHTML syntax. Includes everything HTML elements and attributes, except for outdated presentation ones. Framesets are also not allowed.
Transitional XHTML syntax. Includes all HTML elements and attributes, along with legacy presentation ones. Framesets are not allowed.
Same as XHTML 1.0 Transitional, but allows frames.
Same as XHTML 1.0 Strict, but allows adding modules.

Whichchoose

To sum up, we can say thatis not mandatory element, but its use reduces the risk of problems with displaying the html page in different browsers.

In fact, the following option will suit everyone:

...

indicates which HTML standard your Web page is written according to.


DOCTYPEDescription
HTML5
For all documents.
HTML 4.01
"http://www.w3.org/TR/html4/strict.dtd"> Strict HTML syntax.
Transitional HTML syntax.
An HTML document uses frames.
XHTML 1.0
Strict XHTML syntax.
Transitional XHTML syntax.
The document is written in XHTML and contains frames.
XHTML mobile profile, adds specific elements for mobile phones.
XHTML 1.1
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> This definition has no division into types; the syntax is the same and obeys clear rules.

So, there are several doctypes (strict and transitional, for HTML and XHTML). Which standard to choose is the question.

HTML and XHTML Standards

HTML is a standard markup language for Web documents.

In HTML 4.01 and HTML5 appearance page is separated from its content. Content and structure (headings, paragraphs, links) are specified in HTML. The design (alignment, fonts, colors) is specified by CSS styles.

For example, tag and the align attribute have been deprecated.

XHTML is an extensible Web document markup language based on XML. The XHTML standard is a list of differences between HTML 4.01 and XHTML.

XHTML RequirementsIt is forbiddenNeed to
All tags must be closed.

All tags, attributes and CSS properties must be in lowercase.
All tag attribute values ​​must be enclosed in quotation marks.
The hierarchy must be strictly followed: the first tag is closed last.... ...
A block tag cannot be nested within an inline tag. (After a block element, further output on the page is done on a new line. An inline element does not produce a line break.)
...
...
Boolean attributes are written in expanded form.
Images must have a description

The advantages of the XHTML language are not the strictness of the syntax, but the ability to come up with your own tags.

However, on July 2, 2009, the World Wide Web Consortium (W3C) announced the termination of work on XHTML 2.0, considering the concept of XHTML to be incorrect. A group of programmers switched to working on the HTML5 standard. And although the HTML5 standard has not yet been approved, many sites have already been written on it.

Anyone wondering when HTML5 will be finished can check out the original sources:

The official version of the HTML5 standard is located at: www.w3.org/TR/html5/

Let's make a choice. It's not difficult to do: you shouldn't use the XHTML standard if you don't intend to extend the HTML language.

We won’t dwell on!DOCTYPE, intended for documents using frames: the day before yesterday.

The next question is: which syntax to choose - strict or transitive?

Strict and transitional HTML 4.01 syntax

Transition syntaxes exist to ease the transition to new standard. They will skip a lot of what strict syntax would consider errors.

It’s easier to understand what’s what here with an example. First, let's set the strict syntax.

Strict syntax

Validity check

Validity check

red color.

Compliance of HTML code with the declared standard is called validity, and checking for this correspondence is validation.

To track layout errors, install the FireFox Html Validator add-on.

Let's open our page at FireFox browser, move the mouse over the validator sign:

Double clicking on the validator sign will give a detailed list of errors:


Let's change!DOCTYPE to transition syntax:

Transitional syntax

Validity check

Validity check

Part of the text needed to be highlighted red color.

Launch FireFox. No errors:


Everything seems fine. Maybe we should stop there?

My advice: do a valid layout either in accordance with the strict syntax of HTML 4.01, or directly in HTML5. HTML should be used for its intended purpose, and the design should be left to CSS. In addition, if the site has a valid layout, but it does not display correctly in any browser, then this is definitely a browser problem. New versions of the browser will better comply with the standard and not make mistakes in interpreting valid code. If a complex layout is implemented in an invalid way, then there is no guarantee that new versions of browsers will not crumble it into pieces.

Don't be tempted by the loyalty of transitional syntax, only strict compliance with standards!

Why is a valid layout needed?

It would seem, why bother? After all, browsers often correct small layout flaws automatically, and the site works absolutely fine. But these small, practically unnoticeable errors are nevertheless noticed by search engines. Even one missing tag

- this is a minus in assessing the quality of the site.

It is precisely because of the ability search engines notice any shortcomings in the HTML code and it is recommended to maintain the validity of the layout. In addition, by checking the code for validity, you can find, along with minor flaws, serious errors that were not noticed before.



.

Just imagine: you create a website page, do everything according to the rules, but your browser does not correctly display all the information that you have placed on your page. With what it can be connected?

Incorrect display of data presented on a web page is primarily due to the fact that the browser incorrectly determines the type of document located on the page - DTD.

In turn, this can only be caused by the fact that you used the wrong header for the code. For correct definition DTD type today there is a special tag called Doctype.

It would not be superfluous to mention that this tag has enough long history. It was developed at the same time as Internet Explorer 5 for MacOS and encountered some difficulty reading some pages.

The fact is that the new (at that time) version of the browser exceeded all expectations and simply stopped displaying old website pages properly. And therefore, old pages that were not in the code at that time of this tag, were equipped with a Doctype appearing before the html element.

Why is it necessary to specify the Doctype?

As mentioned above, this tag is inserted into the code of any web document to correctly determine its type. Specifying the document type is required primarily because today there are several HTML versions documents written in different languages. There is also an extended version - XHTML.

Example Doctype tag:

Varieties of the Doctype tag

Today there are several variants of this tag that are used for different versions web documents:

  • Doctype HTML 4.01. The code using this tag looks like this:

    .

    IN in this case strict html is used:

  • ...

    ...

    "http://www.w3.org/TR/html4/strict.dtd">.

    • Transitional versions of Doctype HTML 4.01.
    • HTML5 Doctype looks like this. This tag is suitable for any documents.

    What happens if you use older versions of the Doctype tag?

    The meaning of the Doctype tag is very important, since it is what allows all web pages to work in accordance with the specified standard.

    If you use an incomplete version of a tag, insert it incorrectly, or do not use it in the code at all, your browser will automatically go into “mysterious” mode.

    In this case, the document will be displayed in such a way as if you freely deviated from the standards.

    To date only Opera browser tries to display pages as if they met all standards, regardless of whether Doctype tag or not.

    However, it is worth noting that this browser does not yet fully support all W3C DOM standards, but work on this is already underway.

    Where can I get a quality Doctype tag?

    If you want to receive and use correct tag Doctype, then you can use the www.w3.org service, which is what most webmasters do today.

    Here you can grab the HTML PUBLIC DOCTYPE, which you will need to define HTML 4.01 type web documents, as well as the HTML 5 Doctype and many other tag types needed to create standards-compliant pages.

    An example of using a tag for HTML 5, taken from www.w3.org:

    !DOCTYPE

    Text, text, text, text, text, text, text,

    I hope that this article was useful to you! Good luck!

    Good bad

      In this section of the article we will explain how to use the tag , and also describe its syntax and give practical examples changing text size in HTML.

Hello, dear readers! Continuing CSS theme I want to bring to your attention selectors description of child and context selectors, as well as their comparative analysis, because according to the logic of application they are very similar, although they have some differences.

In my publications I dwelled in some detail on various types CSS selectors: ; and . By the way, in the last article, where we discussed different types attribute selector, I described in some detail how my theoretical calculations can be immediately checked by making changes to the HTML and CSS code online using the built-in Google tool Chrome(). Such editing tools have latest modifications everyone popular browsers, including Firebug plugin for Firefox().

You can also study the theoretical material in this post by editing any page of any website! To do this, just press F12 if you are using Google Chrome or Mozilla Firefox(). Now I’ll present the contents of the p tag, using which we will study as an example child and contextual CSS selectors:

This paragraph includes em and strong formatting tags that highlight text bold And italics.

Using the editing tool described above, I inserted this paragraph directly into this article, entering the appropriate text on the left side of the editing window, as a result of which the text of this paragraph appeared at the very top of the page:


This HTML construct, . This paragraph will be a test subject in today's publication; using its example, I will show how the design of its text changes, depending on which selectors - child or contextual - are used in the CSS rule.

A child element is an element that is located directly inside its parent.. Before proceeding directly to the topic, I will provide a picture that reflects the hierarchy of tags in HTML document using the example of the paragraph whose text is given above and which we will analyze today:

This design is also called an element tree. This figure clearly shows the nesting of containers, which suggests hierarchical relationships between tags. The paragraph tag p is child element in relation to . At the same time, the strong tag is not a child of the div, since it is located in the p container.

Child CSS selector

A child selector in a tree of elements is always located directly inside the parent element, in this case the syntax is writing CSS The selector will be as follows:

The style will be applied to Selector 2, but only if it is a child of Selector 1. Let's look at it in more detail using the above screenshot of the element tree. For example, following the syntax, you can set a rule like this:

P> em (color: green;)

This rule will affect the last word of the paragraph to be “italicized,” since that is what is enclosed between the opening and closing em tags. The em tag is a child of p because it is placed directly inside it, therefore the content text, namely the word “italics”, will be colored in green color.


However, the other em tag is not a direct descendant of the p tag, since it is part of the strong tag, as a result of which the “em and strong formatting tags” part of the paragraph will not be colored.

Contextual CSS selector

It's time to figure it out what is contextual CSS selector . When laying out a particular page on a website, tags are often nested one inside the other. In order for styles for such elements to work correctly, selectors are used that act in some context, hence the name.

If in order for a CSS rule to be applied, the child selector must be located directly inside the parent element (the first nesting level), then for the context selector this is completely unimportant and any nesting level can be applied, the properties of the element will still be transferred from the parent. The syntax is this:

As you can see, a context selector consists of simple selectors separated by a space. For contextual selectors, it is allowed to use two or more nested tags. Let’s now create a CSS rule for the paragraph under test, which I cited above:

P em (color: green;)


As you can see, not only the text of part of the paragraph content, which is directly enclosed in the em formatting tag, that is, the word “italicized,” is colored green, but also a section of the text of another em tag, which is also part of the strong tag. This happened because there is a rule with a context selector, for which the level of nesting is not important, unlike the child selector. This is the fundamental difference between a child and a context selector.

Let's look at another example of how contextual and child selectors interact with our paragraph. Let's write down the following CSS rules for child and context selector:

Div em (color: red;) p> em (color: green;)

After this, our paragraph takes on the following design:


As you can see, a piece of text enclosed in em and strong tags is colored red because the context selector rule is valid for it, that is, the em tag is enclosed in strong and div containers, and the nesting level, as already noted, does not matter .

The question arises: why is the word “italicized,” which is also the content of em, colored green? After all, the context selector rule is relevant for him too. But for this section of paragraph text, the child selector rule is also valid, because it does not contradict the condition that for a child selector, the element must be directly included in the p tag.

The thing is, in CSS there is a law of precedence for CSS properties, located below. That is, in this case, the child selector rule is located lower in the document than CSS styles, written for the context selector of the div container. Therefore, the word “italics” turned green. If you swap them, then the “p> em (color: green;)” rule no longer applies and the “italic” section of the text will be red.

is an element intended for the type of future document (in particular HTML and XHTML). The abbreviation DTD means (document type definition) a description of the document type. This element is necessary so that browsers can understand how they should see and display the future document or web page.
On at this stage for web development there are several types of element. Below in table No. 1, several main types of this element and their brief description are provided.

Table No. 1

Element type Short description
HTML 4.01
Type strict HTML syntax.
Type transitional HTML syntax.
Indicates that the HTML document uses frames.
HTML 5
For all documents.
XHTML 1.0
Type strict XHTML syntax.
Type XHTML transitional syntax.
Indicates that the document is written in XHTML and contains frames.
XHTML 1.1
The developers of XHTML 1.1 expect it to gradually replace HTML. This definition has no division into types; the syntax is the same and obeys clear rules.

Let's look at the structure of a line with an element in order.

Top-level element][Publicity]"[Registration] //[Organization]//[Type][Name]//[Language]" "">

- type of the future document.

Top level element — indicates the top-level element in the document, for HTML this is a tag .

Publicity— the object is a public resource (PUBLIC value) or a system resource (SYSTEM value), for example, such as a local file. For HTML/XHTML the value is PUBLIC.

Registration — reports that the DTD developer is registered with the International Organization for Standardization (ISO). Takes one of two values: plus (+) - the developer is registered with ISO and - (minus) - the developer is not registered. For W3C the value is set to “-”.

Organization — the unique name of the organization that developed the DTD. Officially HTML/XHTML is published by the W3C, and this is the name written in.

Type— type of document being described. For HTML/XHTML the value is specified by the DTD.

Name— a unique document name to describe the DTD.

Language— the language in which the text is written to describe the object. Contains two letters, written in uppercase. For an HTML/XHTML document, indicate English language(EN).

URL— address of the document with DTD.

Here, perhaps, is the basic principle, devices and actions of this element ..
Closing tag for this elementnot required.
As an example givenHTML 4.01:







2024 gtavrl.ru.