DOCTYPE. HTML standards. Valid layout. HTML and XHTML standards. This is a text title
If you open any web page, it will contain typical elements that do not change from the type and focus of the site. Example 4.1 shows the code simple documentcontaining the main tags.
Example 4.1. Web page source
Sample web page
Heading
First paragraph.
Second paragraph.
Copy the contents of this example and save it in the c: \\ www \\ folder as example41.html. After that launch the browser and open the file via the menu item File\u003e Open File (Ctrl + O)... In the Select Document dialog box, specify the file example41.html. The web page shown in Fig. 4.1.
Figure: 4.1. Example execution result
Element is intended to indicate the type of the current document - DTD (document type definition, document type description). This is necessary for the browser to understand how the current web page should be interpreted, since HTML exists in several versions, and there is also XHTML (EXtensible HyperText Markup Language), which is similar to HTML, but differs in syntax. So that the browser does not "get confused" and understands according to which standard to display the web page and it is necessary to set
.
There are several types , they differ depending on the version of HTML they are targeting. Table 4.1. lists the main types of documents with their description.
Tab. 4.1. Valid DTDs
DOCTYPE
Description
HTML 4.01
Strict HTML syntax.
Transitional HTML syntax.
Frames are used in the HTML document.
HTML 5
There is only one doctype in this version of HTML.
XHTML 1.0
Strong XHTML syntax.
Transitional XHTML syntax.
The document is written in XHTML and contains frames.
XHTML 1.1
The developers of XHTML 1.1 anticipate it will gradually replace HTML. As you can see, this definition has no division into types, since the syntax is the same and obeys clear rules.
The difference between strict and transient document descriptions is the different approach to writing document code. Strict HTML requires strict adherence to the HTML specification and is unforgiving. Transitional HTML is more "relaxed" about some code flaws, so this type is preferable in certain cases.
For example, in strict HTML and XHTML, the tag
, but in transitional HTML it can be omitted or omitted. At the same time, remember that the browser will display the document in any case, regardless of whether it matches the syntax or not. Such verification is carried out using a validator and is intended primarily for developers to track errors in the document.
In what follows, we will mainly apply the strict , unless otherwise specified. This will allow us to avoid common mistakes and teach us to write syntactically correct code.
You can often find HTML code without using , the web page will still be shown in such a case. However, it can happen that the same document is displayed differently in the browser when using and without it. In addition, browsers can display such documents in their own way; as a result, the page will "crumble", i.e. will be displayed in a completely different way than the developer needs. To avoid situations like this, always add to the beginning of the document.
Tag defines the beginning of the HTML file, inside it is the header (
) and document body (
).
Document title, as the block is also called
, can contain text and tags, but the content of this section is not shown directly on the page, except for the container
.
Tag is universal and adds a whole class of capabilities, in particular, using meta tags, as this tag is generically called, you can change the page encoding, add keywords, document description and much more. So that the browser understands that it is dealing with the UTF-8 encoding (Unicode transformation format, Unicode transformation format), this string is added.
Sample web page
Tag
defines the title of the web page, this is one of the important elements designed to solve many problems. IN operating system Windows title text is displayed in the left upper corner browser windows (fig. 4.2).
Figure: 4.2. Browser header view
Tag
is required and must be present in the document code.
Be sure to add a closing tag to indicate that the document's title block is complete.
Document body
designed to accommodate tags and content of the web page.
Heading
HTML offers six different levels of text headings that indicate the relative importance of the section after the heading. So, the tag
represents the most important first level heading, and the tag
serves to indicate a level six heading and is least significant. By default, the first level heading is displayed in the largest bold type, and the next level headings are smaller. Tags
...
refer to block elements, they always start with new lineand after them other items are displayed on the next line. In addition, white space is added before and after the title.
Some text can be hidden from display in the browser by making it a comment. Although the user will not see such text, it will still be transmitted in the document, so by looking source, hidden notes can be discovered.
HTML basics contain the basic rules of the HTML language, a description of the structure of an HTML page, relations in the structure of an HTML document between HTML elements.
HTML document is normal text Document, can be created as usual text editor(Notebook), and in specialized, with code highlighting (Notepad ++, Visual Studio Code, etc.)... HTML document has the extension .html.
An HTML document consists of a tree of HTML elements and text. Each element is denoted in the original document by a start (opening) and end (closing) tag (with rare exceptions).
Start tag shows where the element starts, the ending shows where it ends. End tag is formed by adding a slash / before the tag name:<имя тега> … имя тега> ... Between the start and end tags is the content of the tag - content.
Single tags cannot store content directly, it is written as an attribute value, for example, a tag will create a button with text Button inside.
Tags can be nested within each other, for example,
Text
... When investing, you should follow the order of closing ("matryoshka" principle), for example, the following would be incorrect:
Text
.
HTML elements can have attributes (global, which apply to all HTML elements, and their own). Attributes are written in the element's opening tag and contain a name and value specified in the format attribute name \u003d "value". Attributes allow you to change the properties and behavior of the element for which they are set.
Each element can be assigned multiple class values \u200b\u200band only one id value. Multiple class values \u200b\u200bare separated by a space,
... The class and id values \u200b\u200bmust only consist of letters, numbers, hyphens, and underscores, and must begin with only letters or numbers.
The browser views (interprets) an HTML document, building its structure (DOM) and displaying it according to the instructions included in this file (stylesheets, scripts). If the markup is correct, then the browser window will display an HTML page containing HTML elements - headers, tables, images, etc.
Interpretation process (parsing) starts before the web page is fully loaded into the browser. Browsers process HTML documents sequentially from the beginning, while processing CSS and matching style sheets to page elements.
HTML document consists of two sections - heading - between tags
… and the content part - between the tags … .
Web page structure
1. The structure of the HTML document
The HTML language follows the rules contained in the document type declaration file (Document Type Definition, or DTD)... A DTD is an XML document that defines which tags, attributes and their values \u200b\u200bare valid for a particular HTML type. Each HTML version has its own DTD.
DOCTYPE is responsible for the correct display of the web page by the browser. DOCTYPE defines not only the HTML version (like html), but also the corresponding DTD file on the Internet.
...
Elements inside a tag , form a document tree, the so-called document object model (DOM)... Moreover, the element is the root element.
Figure: 1. The simplest structure of a web page
To understand the interaction of elements of a web page, it is necessary to consider the so-called "Family relationship" between elements. Relationships between multiple nested elements are categorized as parent, child, and sibling.
Ancestor - an element that contains other elements. In Figure 1, the ancestor for all elements is ... At the same time, the element
is the ancestor for all the tags it contains:
,
, ,
Descendant - an element located within one or more types of elements. For example,
is a descendant and element
Is a descendant of both
and .
Parent element - an element associated with other elements of a lower level, and located in the tree above them. Figure 1
and ... Tag
Parent only for .
Child element - an element directly subordinate to another element of a higher level. In figure 1 only elements
,
,
AND
Nursing element - an element that has a common parent with the considered element, the so-called siblings. Figure 1
and - elements of the same level, as well as elements
,
and
They are sisters among themselves.
1.1. Element
1.2. Element
Section
... contains technical information about the page: title, description, keywords for search engines, encoding, etc. The information entered in it is not displayed in the browser window, but contains data that tells the browser how to handle the page.
1.2.1. Element
Required section tag
is the tag ... The text placed inside this tag is displayed in the title bar of the web browser. The length of the title should be no more than 60 characters in order to completely fit into the title. The title text should contain as complete a description of the content of the web page as possible.
1.2.2. Element
Optional section tag
is a single tag ... It can be used to set a description of the page content and keywords for search engines, the author of the HTML document, and other metadata properties. Element can contain multiple elements because, depending on the attributes used, they carry different information.
The description of the page content and keywords can be simultaneously specified in several languages, for example, in Russian and English:
Using the tag you can prohibit or allow the indexing of a web page by search engines:
To automatically reload the page after a specified period of time, you need to use the refresh value:
The page will reload in 30 seconds. To send a visitor to another page, you need to specify the URL in the url parameter:
Table 2. Tag Attributes
Attribute
charset
Specifies the character encoding for the current HTML document:
content
Contains arbitrary text that defines the value associated with the http-equiv or name attribute, depending on their value.
http-equiv
Controls browser actions on a given web page (equivalent to HTTP headers). When rendering the page, the browser will follow the instructions given in the attribute: default-style indicates the preferred style for use on the page. The content attribute must contain the element ID which refers to a CSS stylesheet, or element id
using element ... The element does not require an end tag. This element defines the relationship between the current page and other documents. There can be several such elements on the page. The entry will look like this:
Table 4. Tag Attributes
Attribute
Description, accepted value
crossorigin
Specifies whether CORS (a browser technology that allows a web page to access resources from another domain) should be used when retrieving an image from a site. anonymous - the browser automatically adds the Origin header to the cross-domain request, which contains the name of the domain from which the request was made. If the server does not respond with the CORS header Access-Control-Allow-Origin: * (or the domain name instead of an asterisk), then the image upload will be blocked. use-credentials - if the server does not provide credentials using Access-Control-Allow-Credentials: true, then image upload will be blocked.
href
The main attribute of the tag, the value is the path to the file with styles.
hreflang
Determines the language of the text in the referenced document.
media
Specifies the type of device to which the link resource should be applied.
nonce
A randomly generated string variable on the server that specifies the rules for using inline styles to protect content. The attribute value is a string of text.
rel
The attribute defines the relationship between the current document and the referenced document. alternate - a link to the same document, but in a different format (for example, printable pages, translation, mirror, RSS or Atom feed),
.
archives - indicates that the referenced document is of historical interest. The link can point to a collection of records, documents, and other materials. author is a link to the page about the author of the document or to the page with the contact details of the author. bookmark refers to the closest ancestor of the article that is the linking link, or to the section of the article that is most closely related to the element if there is no parent. external is used to indicate that the linked page is not part of this site. first specifies a link to the first document in a sequence of documents. help is a link to a document with help. icon defines the path to the icon that will be used for the current document. last specifies a link to the last document in the document sequence. license refers to the copyright information for the document. next indicates that this document is part of a series and that the link leads to the next document in the series.
nofollow indicates that the link is not approved by the author of the page or that the link is of a commercial nature. noreferrer indicates that the client request header containing the url of the request source should not be passed when clicking on the link. pingback specifies the address of the pingback server, which makes it possible for the blog to automatically notify sites that link to it. prefetch specifies that the linking file should be cached in advance. prev indicates that this document is part of a series and that the link points to the previous document in the series.
search indicates that the referenced document contains a search interface and related resources. sidebar indicates that the referenced document, if possible, will be shown in an additional browser context, and some browsers, when clicking on the hyperlink, open a window to add the link to the bookmark bar. stylesheet is a link to an external file that will be used as the stylesheet for this document. tag indicates that the tag the hyperlink points to is for the given document. up indicates that the page is part of a hierarchical structure and that the hyperlink leads to a higher level of the resource in the structure.
sizes
Specifies the size of the icons for visual display. The sizes attribute is used only in conjunction with rel \u003d "icon", and can take the following values: widths height - defines a list of sizes separated by spaces, each size must be in the format - widths height (icon sizes are set in pixels), for example:
; any - the icon can be scaled to any size.
title
Specifies the title of the link or the name of a set of alternative style sheets. The attribute value is text.
type
Specifies the MIME type of the document being referenced. In this case, it takes the value "text / css".