Elements used in the body of an HTML document. Let's analyze this example


An HTML document consists of body text and tags. Essentially, an HTML document is a text file and you can use a regular text editor such as Notepad to create it.

HTML documents have a strictly defined structure and must begin with a tag and end with a closing tag. This pair of tags tells the browser that this is indeed an HTML document.

An HTML document consists of a header section and a body section. The headers section is enclosed between and tags and contains information about the document as a whole. In particular, this section should contain tags and , between which the title of the document is placed. Browsers use this title to fill the title bar of the browser window.

The main text is located in the body of the document, which is specified by and tags. The BGCOLOR attribute is used to change the background of the document, and the TEXT attribute is used to set the font color. The values ​​of these attributes are a symbolic color constant or a hexadecimal number that forms the color according to the red-green-blue scheme.

The four paired tags listed define the basic structure of an HTML document. They appear or are implied in all HTML documents.

In fact, it is possible to determine the location of the main structural tags even in their absence. Therefore, if the tags , , and the corresponding closing tags are omitted, then the browser program itself will determine the place where they should be located. The tag is considered mandatory, but skipping it will not cause catastrophic consequences. However, when creating Web pages, it is not recommended to omit these tags, since it is unknown how the browser installed on the user’s computer will behave.

Paired tags affect the portion of the document between the opening and closing tags. This part of the document is considered as an element HTML language. For example, the BODY element includes an opening tag, the body of the element, and a closing tag. HTML language elements are divided into block and text. Block elements refer to paragraph-level pieces of text. Text elements describe the properties of individual phrases and smaller parts of text. When creating an HTML document, it is advisable to adhere to the following nesting rules:

    elements must not intersect. If the opening tag is inside an element, then the closing tag must be inside the same element;

    block elements can contain nested block and text elements;

    text elements can contain nested text elements;

    text elements cannot contain nested block elements.

Document title

Functional sections of the document

The HTML language is designed to describe the functional sections of a document. In many regular documents, the main functional sections are headings and paragraphs.

HTML supports six levels of internal document headings. They are marked with tags from and to and . On a computer screen, these headings are displayed in fonts of different sizes. In accordance with the ideology of the HTML language, the text, which is essentially a heading, must be marked using one of these tags. Use formatting tags that change font size and style in in this case do not do it.

To designate regular paragraphs, use the tag

And accordingly the closing tag

. Tags that describe regular paragraphs are optional, but if they are present, browsers will clearly track the boundaries between paragraphs.

To improve text readability, browsers display a blank line between paragraphs. An effective means of creating separators in text are horizontal stripes (rulers), visually dividing the document into parts. A horizontal ruler is created by the tag. This is a single tag and does not have a pair.

When creating an HTML document, keep in mind that multiple spaces between words and new lines are ignored when the document is played back by the browser.

To move to a new line without creating a paragraph, use the tag
.

Functional sections of the document

Main title

Subtitle

These lines are displayed together,

despite the fact that in the document

they are separated

from each other.

The closing paragraph tag is optional.

The paragraph start tag is more important than the actual newline.

Text after horizontal ruler
split into two lines

When creating a website, the first thing you need to imagine is how the web page is formed. This is a kind of “foundation” in website building. Therefore, before delving into more complex website creation technologies, it is recommended to have at least basic knowledge of HTML. In this lesson we will get acquainted with HTML, analyze the structure of an HTML document and practical examples Let's consolidate the acquired knowledge.

What is HTML?

HTML stands for HyperText Markup Language. This language is responsible for exactly how hypertext will be displayed on site pages. Now let's figure out what hypertext is? It's no secret that a single web page can contain a lot of different types of information, be it text, some tables, graphs, videos, audio, etc. So, all this information can be called in one word - hypertext.

Note that HTML is a markup language, not a programming language. IN given language there are no logical functions and it is impossible to make any mathematical calculations on it. HTML pages have the extension .html or .htm and are processed by browsers - IE, Mozilla Firefox, Google Chrome, Yandex Chrome, Opera, etc.

Now let's figure out how the browser understands what and how to display on a web page? It's very simple. The hypertext markup language HTML has built-in commands called tags. It is by them that the browser is oriented.

HTML Document Structure

Any HTML document (web page) must have a certain structure. This will avoid possible problems when opening pages in browsers. As an example, let's look at a page that contains following HTML code:

), between which the identifier (name) of the tag is written (in our example it is in), and, possibly, its parameters. The only exception to this rule is comment tags with more complex delimiters (). The names of tags, as well as their parameters, can be written in any register. For consistency, most tags in this book are written in capital letters.

Majority HTML tags used in pairs, i.e. for a certain tag, let’s call it opening, the document has a corresponding closing tag. By HTML rules The closing tag is written in the same way as the opening tag, but with a / (forward slash) in front of the tag name. The only fundamental difference between paired tags is that closing tags do not use parameters.

Tags that require corresponding end tags will be called container tags. We will call everything written between the corresponding opening and closing tags the contents of the container tag. Sometimes the end tag can be omitted. For example, for a tag describing data for a table cell , the corresponding closing tag You can always omit it. The end of data for a table cell will be recognized by the appearance of the next tag or table line ending tag.

There are a number of tags for which the end tags are omitted by most document authors. An example would be a list item tag

  • or paragraph tag

    Modern browsers will in many cases format documents correctly if some end tags are omitted, but this practice cannot be recommended.

    Some tags don't require end tags at all. Examples include the image insertion tag , forced line feed
    , indication of the base font, etc. Often, from the very purpose of the tag, you can guess whether it needs a final one.

    There are general rules for how browsers interpret tags. Unlike programming languages, in which erroneous statements lead to the issuance of corresponding messages at the compilation stage of the program and require editing, in HTML it is not customary to react to incorrect tag entries. An incorrectly written tag or its parameter should simply be ignored by the browser. This is a general rule for all browsers, which applies not only to erroneously written tags, but also to tags that are not recognized by this version of the browser. An example would be tags that were proposed and implemented for a particular browser and unknown for another. For example, a container tag that serves to provide alternative information to browsers that do not support frame structures will not be recognized by such browsers. A browser that supports frames, when it encounters a tag, will skip all the information contained in it. And a browser that is not familiar with frames will naturally not understand the tag. However, according to the above rule, this tag will simply be skipped, but all subsequent information will be displayed.

    Tags can be written with parameters or attributes (from English, attribute). In this book we will use the term parameter most often. Sets acceptable parameters are individual for each tag. General rules The parameter entries are as follows. The tag name may be followed by parameters, separated by spaces. The order of the tag parameters is arbitrary. Many parameters require specifying their values, but some parameters have no values ​​or can be written without them, taking default values. If a parameter requires a value, it is indicated after the parameter name using an equal sign. The parameter value can be written in quotes or without them. The only case in which you cannot do without quotes is when there are spaces in the parameter value. In parameter values ​​(as opposed to tag names and parameters themselves), case is sometimes important. Here's an example of a tag entry with parameters:

    Here for the tag

    two parameters are specified. The first BORDER parameter is specified without a value. The second ALIGN parameter is left.

    The subsequent chapters of the first part of the book will describe the purpose of HTML language tags and their parameters. In general, tags can have various parameters, however, there are a number of parameters that are the same for almost all tags. Let's mention here Common parameters tags, so as not to talk about them anymore when describing each tag.

    All tags that can be used in a section of an HTML document can have the parameters CLASS, ID, LANG, LANGUAGE, STYLE and TITLE. The use of these parameters is useful, first of all, when styling documents, which will be discussed in the second part of the book.

    CLASS, ID, STYLE parameters are supported Internet Explorer, starting with version 3.0, and Netscape, starting with version 4.0. These parameters are needed when using styles.

    Parameters LANG, LANGUAGE, TITLE are supported only by Internet Explorer starting from version 4.0. These parameters indicate, respectively, the language used (for example, for Russia: LANG=ru), the language for writing scripts (for example, LANGUAGE=JavaScript), as well as the text of the tooltip displayed when you hover the mouse pointer over this element(TITLE).

    IN modern HTML, in addition to language tags and their contents, in source HTML code Script codes (javascript or VBScript) are also recorded. In the first part of the book this is hardly mentioned anywhere, but part two is entirely devoted to the use of scripts.

    Completing general review HTML, note that the simplest HTML documents are ordinary text files, to view and edit which you can use any text editor. These files usually have the extension HTM or HTML.

    HTML Specifications

    The HTML language gained popularity in the mid-90s due to the exponential growth of the Internet. By this time, there was a need to standardize the language, since various companies that developed software for Internet access offered their

    variants of HTML instructions, the number of which kept growing and growing. The time has come to come to some kind of unified agreement regarding the use of HTML language tags.

    The work of creating the HTML specification was undertaken by an organization called World Wide Web Consortium (abbreviated as W3C). Her task was to draw up a specification reflecting modern level development of language capabilities, taking into account the various proposals of browser development companies. Thus, in November 1995, the HTML 2.0 specification appeared, designed to formalize the practice of using HTML that had developed by the end of 1994.

    The approval scheme for specifications is as follows. The W3C consortium releases a draft specification, after discussion of which it releases a so-called draft version of the specification and offers it for discussion at certain period. After a period of discussion, the working version of the specification may become a recommendation, i.e., an officially accepted version of the HTML specification.

    Shortly after the 2.0 specification was released working version specification 3.0, whose comment period expired in September 1995. This specification was never adopted as a formal recommendation. It was planned to include a wide variety of tags and capabilities specific to individual browsers, however, the W3C Consortium has not found a way to develop a good specification for such large number instructions.

    After much deliberation, HTML 3.2 was released in May 1996. The project was based on some of the tags available in version 3.0, which showed stability in operation. After several months of discussion, version 3.2 became a proposed specification in September 1996 and a formal recommendation in January 1997.

    July 1997 saw the release of the proposed HTML 4.0 specification, which became an official recommendation in December 1997. This is the latest accepted specification to date.

    In the following brief overview history of the development of the HTML language, it is hardly worth describing in detail the features of various specifications, especially since in real life developers do not always follow the recommendations of the Consortium. Let us note just some of the ideas underlying the latest specification.

    The key idea in the HTML 4.0 specification was to separate the description of the structure of the document from the description of its presentation on the monitor screen. Experience has shown that separating document structure and presentation reduces the cost of supporting a wide range of platforms, environments, etc., and also makes document revisions easier. In accordance with this idea, methods for describing representations should be used more widely.

    document using style sheets, rather than specifying specific presentation data interspersed with the content of the document. To implement this idea in the HTML 4.0 specification, a number of tags used to directly specify the form of presentation of HTML elements have been canceled. Tags canceled for this reason include , , , , , . Among other canceled tags, we note , , , . Instead of canceled tags, they are offered alternative options implementation of relevant opportunities, which we focus on Special attention in this book.

    The concept of a deprecate tag is as follows. If a tag is deprecated in this language specification, it means that browsers should continue to support such tags for now, but their use is not recommended. In future specifications, these tags may be made obsolete. Obsolete tags may no longer be supported by browsers. In the HTML 4.0 specification, only three tags are deprecated: , AND . Information about which tags are included in the specification can be obtained from the table given in Appendix A1.

    Official information about the HTML specification can always be obtained from the W3C Web site at http://www.w3.org/TR/. Specification 4.0 is located at http://www.w3.org/TR/REC-htmI40-971218.

    Note that, logically, the official specification should play the role of a guiding and guiding force, ensuring that information is presented in the same way across different browsers. This is the ideal option to strive for. In reality, things are not so good. Constantly appearing new ideas, implemented by development companies in their browsers and promoted by them. Successful ideas take root and are then picked up by other developers. Some of the features remain specific to the individual browser. Successful designs eventually end up in the specification and become generally accepted. Thus, the process of improving browser capabilities and clarifying the specification is ongoing, influencing each other.

    Document structure

    The first tag to begin describing HTML documents is the . He must always start document description, and the tag should complete the document description. These tags indicate that the lines between them represent a single HTML document. The document itself is an ordinary ASCII text file. Without these tags, a browser or other viewer may not be able to identify the document format and interpret it correctly.

    Most often, the tag is used without parameters. IN previous versions the VERSION parameter was used, deprecated by the HTML 4.0 specification. This parameter has been replaced by the tag.

    Majority modern browsers can recognize a document that does not contain tags and yet their use is highly desirable.

    The document itself is located between a pair of tags. A document can consist of two sections - a header section (beginning with the tag ) and a content section of the document (beginning with the tag ). For documents describing frame structures, the FRAMESET section (with the tag) is used instead of the BODY section. Next, we will consider the rules for compiling the HEAD and BODY sections of the document. The construction of documents containing frames is discussed in Chapter 5.

    HEAD document section

    The HEAD section of a document defines its title and is not a required tag, but a well-written title can be quite useful. The purpose of the header is to present necessary information for the program that interprets the document. Tags located inside the HEAD section (except for the title of the document described by the tag) are not displayed on the screen.

    The header section opens with the tag . Typically this tag comes immediately after the . The closing tag indicates the end of this section. Between the mentioned tags are the remaining tags of the header section.

    Document's name

    The container tag is the only required head tag and serves to give the document a title. It is usually shown in the title bar of the browser window. The tag should not be confused with the document file name; on the contrary, it represents text string, completely independent of the file name and location, which makes it quite useful. The file name is strictly defined operating system the computer on which it is stored. You should also distinguish the title of the document (with the tag) from headings within the document, usually marked with tags.

    Note

    The mandatory title of the document, generally speaking, has the character of a strong recommendation. A document without a tag will also be displayed by browsers. Wherein various browsers will display as the window title various information. So early versions Netscape browser displayed the line "No title". Other browsers either show nothing or display the address of the downloaded file, repeating the information in the browser's Location panel.

    The title of the document is written between the tags and and is a line of text. In principle, the name can be of unlimited length and contain any characters except some reserved ones. In practice, you should limit yourself to one line, keeping in mind that the name appears in the title bar of the browser window. You should also remember what will remain of the document title when minimizing the browser window. It is recommended to limit the length of the document title to 60 characters. You can see how the title is displayed in the browser window in any figure in this book, which gives an example of how a document is displayed.

    By default, the text contained in document title, used when creating a bookmark for a document. Therefore, for greater information content, avoid faceless names (Home Page, Index, etc.). Such words used as bookmark names are usually completely useless. The title of the document should briefly describe its content. Note that when displaying documents with a frame structure on the screen, when a separate document with its own name is loaded into each frame, only the name of the main document will be visible on the screen. However, specifying the title of individual documents intended to be loaded into frames is also strongly recommended. This issue is discussed in more detail in Chapter 5.

    The importance of the document title is determined by the following fact. Since the tag is located almost at the very beginning of the HTML file, once the document starts loading, it is the first thing that is displayed. Next, the main content of the document is loaded, and the browser begins formatting the document in the window. This process, generally speaking, depending on the content and structure of the document, as well as the connection speed, can take a long time. For quite a long time, the user will contemplate a blank screen, the only informative line of which will be the title of the document. Quite often (if the connection is lost or if the user does not want to wait for the document to finish loading), all information about the document ends there.

    Relationship with other documents

    Often HTML documents are interconnected, that is, they have links to each other. Links can be either absolute or relative. Both of them have disadvantages. Absolute links can be too cumbersome and stop working if a lower document in the hierarchy is moved. Relative links are easier to enter and update, but this link is also broken if the document that is higher in the hierarchy is moved. Both types of connections can be broken when transferring a document from one computer to another.

    It often happens that a user has downloaded a large document onto his machine and disconnected from the network to study it in detail. All links in the local copy of the document will stop working. To “reanimate” them, you will have to return to the original document located on the remote computer.

    Fortunately, the HTML developers anticipated this problem and added two tags, and , that are included in the header to ensure that the connection between documents is not broken.

    Tag

    The tag is used to indicate the full base URL of the document. With its help, a relative link continues to work if the document is moved to another directory or even to another computer. The tag works similarly to the MS-DOS path command, which allows the viewer to determine the link to the document you are looking for, even if it is in a document that is higher in the hierarchy, located on another computer.

    The tag has one required HREF parameter, followed by the full URL of the document. Below is an example of using the tag.

    Note base address

    The tag tells the browser where to look for the file. If the user is working with a local copy of the file and his machine is not disconnected from the network, the News icon image will be found and shown in the browser window.

    Tag

    Even if the tag allows you to find the file, the question of the relationship between the documents remains open. The importance of these relationships increases in proportion to the complexity of your documents. In order to maintain a logical connection between them, the tag is introduced into HTML.

    A tag indicates a relationship between the document containing the tag and another document or object. It consists of a URL and parameters that specify document relationships. The document title can contain any number of tags. Table 1.1 describes the tag parameters and their functions.

    Table 1.1. Tag options

    Here are examples of a tag with parameters:

    The first line indicates a link to the document's table of contents file (toc.html - table of contents) with a direct contents relationship. The second line describes the relationship to the document's author URL (with the reverse made relationship).

    Many different relationships can exist between documents. Examples of other REL parameter values: bookmark, copyright, glossary, help, home, index, toc, next, previous. The REV parameter can also take the following values: author, editor, publisher, owner.

    Tag

    The development of new hypertext markup language specifications takes a long time, and during this time, browser companies manage to release several versions of their products. Therefore, another tag can be added to the head section to allow document authors to identify non-HTML information.

    This information is used by the browser for actions that are not covered by the current HTML specification. You won't need the tag to create your first HTML documents, but you'll likely need it as your pages become more complex.

    Example:

    The Netscape Navigator and Internet Explorer browsers will interpret this entry as an instruction to wait 60 seconds and then load a new document. This instruction is often used when changing the location of documents. A small document with the given string can be left at the document's old location to automatically link to its new location.

    Next line:

    instructs the browser to reload the page every 60 seconds. This can be useful if the data on the page is updated frequently, such as when tracking stock prices.

    The use of the element to solve some typical problems has become very popular. An example would be specifying keywords used by search engines. This method allows you to include additional words in the document index that may not be explicitly included in its content. To do this, the name of a certain property is specified in the tag as the value of the NAME parameter. And using the CONTENT parameter, the value of this property is specified, for example:

    The HTML specification does not define any specific names for the properties written in the . However, there are several commonly used properties, for example, description, keywords, author, robots, etc.:

    The given tags could well be indicated, for example, for the electronic version of this book.

    The tag can have the parameters specified in the table. 1.2.

    Table 1.2. Tag options

    Another important purpose of the tag is to indicate the text encoding. So, for text in Russian in Windows encoding, you need to write the following line:

    Other header elements

    There may be two more tags in the document header section - and . Their purpose is related to the use of style sheets in a document and writing scripts. These issues are discussed in detail in the second part of the book.

    Document section BODY

    This section of the document contains its content. Most of the tags discussed later in this chapter and subsequent ones should be located in this section of the document. Here we will consider only some general issues.

    The BODY section of the document must begin with the tag and end with the tag, between which the entire content of this section is located. Strictly speaking, the presence of these tags is not required, since browsers can determine the beginning of the content of the document based on the context. However, their use is recommended.

    The tag has a number of parameters, none of which are required. The list of parameters is given in table. 1.3.

    Table 1.3. List of tag parameters

    Parameter

    Purpose

    ALINK

    BACKGROUND

    Points to the URL of the image that is used as the background

    BOTTOMARGIN

    Sets the border of the document's bottom margin in pixels.

    BGCOLOR

    Specifies the background color of the document

    BGPROPERTIES

    When set to FIXED, the background image does not scroll

    LEFTMARGIN

    Sets the left margin of the document in pixels.

    LINK

    Specifies the color of a link that has not yet been viewed

    RIGHTMARGIN

    Sets the border of the document's right margin in pixels.

    SCROLL

    Sets the presence or absence of scroll bars in the browser window

    TEXT

    Defines the text color

    TOPMARGIN

    Sets the border of the document's top margin in pixels.

    VLINK

    Specifies the color of an already viewed link

    The use of the BACKGROUND and BGCOLOR parameters, which determine the background of the document, is discussed in detail in.

    The BGPROPERTIES parameter, which accepts a single value of FIXED, is supported only by Microsoft Internet Explorer.

    The BOTTOMMARGIN, LEFTMARGIN, RIGHTMARGIN, and TOPMARGIN parameters, which specify the distance in pixels between the edges of the text and the corresponding window edges, as well as the SCROLL parameter, are recognized only by Microsoft Internet Explorer, starting with version 4.0.

    The ALINK, LINK, TEXT, and VLINK parameters determine the colors of links and document text.

    In HTML, colors are defined by hexadecimal numbers. The color system is based on three primary colors - red, green and blue - and is designated RGB. Each color is given a hexadecimal value ranging from 00 to FF, which corresponds to a range of 0-255 in decimal. These values ​​are then combined into a single number, preceded by a # symbol. For example, the number #800080 represents the color purple. In order not to remember sets of numbers, you can use the names of colors instead, which are given in Appendix P2. Early versions of browsers only recognized the names of 16 standard colors, marked with asterisks in the application. Modern versions of browsers recognize all 140 color names.

    Text formatting

    This section will look at the possibilities of formatting individual characters in the text of a document.

    Block level tags and sequential tags

    Some HTML tags that may appear in the BODY section are called block level tags, while others are called inline tags or, otherwise known as text level tags, although this division of tags the levels are to a certain extent arbitrary.

    The difference between the levels of HTML tags is that block level tags can contain sequential tags and other block-level tags, while sequential tags contain only data and other sequential tags. Block tags describe larger document structures than sequential tags.

    By default, these types of tags are placed differently in the description text: block-level tags start on a new line, while sequential tags do not.

    Logical and physical formatting

    To format the text of HTML documents, a whole group of tags is provided, which can be divided into logical and physical formatting tags.

    Logical formatting tags denote (by their names) the structural types of their text fragments, such as program code (tag), quote (tag), abbreviation (tag), etc. (see descriptions of these and other similar tags in the following section). Using tags and you can, for example, mark individual fragments as highlighted or highly highlighted. Note that we are talking about structural markup, which does not affect the specific screen representation of the fragment by the browser. Therefore, such markup is called logical. Browsers display logical formatted snippets on the screen in a specific way by default. The display type has nothing to do with the fragment's structural type (i.e., the name of the logical formatting tag), but can be easily overridden.

    Physical formatting tags determine the format for displaying the text fragment specified in them in the browser window (according to the preferences of the document author). For example, to display a snippet in italics, you can use the italics tag . This and other commonly used physical formatting tags are described later in the “Physical Text Formatting Tags” section of this chapter.

    For a long time, there have been debates between developers of HTML documents about the advantages and disadvantages of one or another approach. With the release of the HTML 4.0 specification, this debate ended in favor of the use of logical formatting, as the principle of separating document structure from its presentation was proclaimed. Indeed, only on the basis of logical formatting can one flexibly control the presentation of a document using modern methods (based on style sheets, dynamically changing documents, etc.).

    However, physical formatting can currently be used freely. The HTML 4.0 specification deprecated some physical formatting tags, but they are still supported by all browsers. Note that some logical formatting tags, designed to replace individual physical formatting tags, are not recognized by all browsers, which makes their use extremely inconvenient. An example is a logical tag, which is recommended to be used instead of a physical tag.

    The tags discussed below relate to text-level tags, that is, they are designed mainly to mark small groups of characters. Some tags can also specify markup at the block level.

    Logical text formatting tags

    Tag

    The tag marks its text as an abbreviation (ABBReviation). Although this tag is included in the HTML 4.0 specification, it is not currently supported by any browser.

    Tag

    Tag. Just like the tag, it is used to mark abbreviations. It is recommended to use this tag to mark so-called acronyms, i.e. spoken words consisting of abbreviations. The tag may in the future be used for non-visual display of elements, for example, in speech synthesis.

    This tag is convenient to use in combination with the TITLE parameter, as the value of which you can specify the full form of the abbreviation. Then visual browsers, when you hover the cursor over text marked with the tag, will display the full name in the form of a tooltip.

    Note that the tag is recognized only by the Microsoft Internet Explorer browser. Example:

    SPbGITMO - one of the leading technical universities in St. Petersburg

    Tag

    The tag is used to mark quotes or titles of books and articles, links to other sources, etc. Browsers usually display such text in italics. Example:

    Nevskoe Vremya is one of the most popular city newspapers in St. Petersburg

    Tag

    A tag marks its text as a small piece of program code. Typically displayed in monospace font. This tag should not be confused with the Block-level element tag, which should be used to mark large chunks (listings) of code.

    For example:

    An example of the simplest operator in the C programming language:

    puts("Hello, World!");

    There is another difference in the use of tags and In program code, the presence of several consecutive spaces is often important. Their display will only be saved when using the tag.

    Tag

    The tag marks its text as deleted. This element is useful for marking changes made to a document from version to version. A tag can be used as a text-level element and as a block-level element.

    The tag has two optional parameters: CITE and DATETIME. The value of the CITE parameter must be a URL to a document explaining why the fragment was removed.

    The DATETIME parameter specifies the deletion date in the format: YYYY-MM-DDThh:mm:ssTZD, which specifies the year, month, day, hours, minutes and seconds of deletion, as well as the time zone (Time Zone). For example:

    The latest accepted HTML markup language specification is version 3.2 4.0

    Tagged text is usually displayed as strikethrough text. The HTML 4.0 specification gives preference to this tag over the physical formatting tag or the tag, which denotes strikethrough text. However, the tag

    Tag

    The tag marks its text fragment as a definition (DeFinitioN). For example, this tag can be used to mark a term when it appears in the text for the first time. Example:

    Internet Explorer is a popular Web browser

    The tag is only supported by Microsoft Internet Explorer. Displayed in italics by default.

    Tag

    The tag marks its text as an insertion (INSertion). This element is useful for marking changes made to a document from version to version. A tag can be used as a text-level element and as a block-level element.

    The tag has two optional parameters: CITE and DATETIME. The value of the CITE parameter must be a URL to a document explaining the details of the additions made.

    The DATETIME parameter specifies the date of insertion in the format: YYYY-MM-DDThh:mm:ssTZD, which specifies the year, month, day, hour, minutes and seconds of insertion, as well as the time zone (Time Zone).

    Text tagged with is usually displayed as underlined text. The tag is currently only recognized by Microsoft Internet Explorer.

    Tag

    Tag (EMphasis - highlighting, underlining) is used to highlight important text fragments. Browsers typically display this text in italics. Example:

    Example of highlighting individual words of text

    .

    Tag

    The tag marks text as being entered by the user from the keyboard. Typically displayed in monospace font, for example:

    To launch a text editor, type: notepad

    The use of this tag is preferable to the use of the physical formatting tag.

    Tag

    The tag marks short quotes in a line of text. Unlike a block-level tag, the display does not separate marked-up text with blank lines. Typically displayed in italics. The tag (unlike ) is currently only recognized by Microsoft Internet Explorer.

    The tag has a CITE parameter, the value of which can be the source of the quote.

    Tag

    The tag marks the text as a sample (SAMPle). A common use of this tag is to mark text output from programs (sample output). It is also used to highlight multiple characters in a monospace font.

    The use of this tag is preferable to the use of the physical formatting tag. For example:

    As a result of the program's operation, the following will be printed: Hello, World! .

    Tag

    The tag is usually used to highlight important text fragments. Browsers typically display this text in bold font. Example:

    St. Petersburg is located at the easternmost tip of the Gulf of Finland at the mouth of the Neva River< /STRONG>

    The use of this tag is preferable to the use of the physical formatting tag. The tag usually marks more important fragments of text than those marked with the tag.

    Tag

    The tag marks the names of program variables. Typically this text is displayed in italics. Example:

    Set the value of variable N

    A display of some of the examples given in describing logical text formatting tags is shown in Figure. 1.1. The figure shows how when you hover the mouse over text marked with the tag, a tooltip is displayed.

    Rice. 1.1. Text formatting examples

    You've probably noticed that some elements give the same result. Moreover, some elements may not change the presentation of a piece of text on the screen in any way. A legitimate question may arise: why was such a variety of formatting elements created?

    The answer is in the name of this group of elements. They are designed to place logical emphasis, highlight logical parts and emphasize the essence of statements. Their use is very relevant, since, probably, in the near future the capabilities of browsers will increase, for example, it will become possible to search for citations on the Web, and maybe the next generation of browsers will learn to read documents aloud. In addition, nothing prevents document authors today, using style sheets, from setting the desired display for any of the tags, overriding the default values.

    Physical text formatting tags

    Here is a description of physical formatting tags. Some of them are not recommended for use by the HTML 4.0 specification for the reasons given above. Some tags have been deprecated by the HTML 4.0 specification, but they continue to be supported by browsers.

    Tag

    The tag displays text in bold font. In most cases, it is recommended to use a logical formatting tag instead of a tag. For example:

    This is a bold font.

    Rice. 1.2. Examples of physical text formatting (Netscape browser)

    Tag

    Tag displays text in italics. For most cases, it is recommended to use the , , or tags instead of this tag, since the latter better reflect the purpose of the selected text. For example:

    Selection italics

    Tag

    The tag displays text in a monospace font. For most cases, it is better to use the , or tags instead of this tag. Example:

    This is a monospace font.

    Tag

    Tag displays text underlined. Canceled tag. It is recommended to use or tags instead. For example:

    Example underscores text

    Tags and

    Tags display text with a horizontal line through it. Canceled tag. The tag should be used instead. For example:

    Example of strikethrough text.

    Currently, the tag is not supported by all browsers, so for now it is recommended to use it in combination with the tag. Namely, you can put a couple of tags inside a container tag

    ... .

    Tag

    The tag displays text in a font larger (than the untagged part of the text) size. Instead of this element, it is better to use heading tags, for example,

    Larger font size.

    Tag

    The tag displays text in a smaller font size. Since there is no tag in HTML that is opposite in effect to the tag, the tag can be used for these purposes. Most browsers support nested tags, but this approach is not recommended. For example:

    Smaller font size.

    Tag

    The tag moves text below the line level and displays it (if possible) in a smaller font size. Convenient to use for mathematical indices. For example:

    Example font for subscript.

    Tag

    The tag moves the text above the line level and displays it (if possible) in a smaller font size. Convenient to use for assigning powers of numbers in mathematics. For example:

    Example font for superscript.

    Tag

    The tag displays blinking text. This tag is not part of the HTML specification and is only supported by the Netscape browser. Experienced developers rarely resort to using this tag, since the presence of blinking characters on the page annoys many users.

    Tag

    A container tag is analogous to a block level tag. Can be used when you need to mark a piece of text to set its properties, and cannot use any other structural formatting tag.

    The Microsoft Internet Explorer browser additionally allows the use of the following tag parameters: DIR, DATAFLD, DATAFORMATAS, DATASRC. A description of the parameters can be found in the second part of the book.

    Rice. 1.3. Using nested text formatting tags

    Formatting tags can be nested inside each other. In this case, you need to carefully ensure that one container is located entirely in another container. In Fig. Figure 1.3 shows an example of nesting an italic element within a bold element. The following HTML code fragment is used:

    This is a bold font.

    This italics.

    And here is the text bold and italic

    Tag

    The tag specifies the font parameters. It refers to text-level physical formatting tags.

    Assigning font parameters directly in the document text violates the basic idea of ​​separating the content of the document and describing the form of presentation of the document. Therefore, in the HTML 4.0 specification this tag, as well as the tag, are classified as deprecated. Their further use is not recommended.

    Despite these dire warnings, it appears that physical formatting can be considered acceptable for the simplest documents. In addition, the easiest way to start learning the basics of formatting is with the rules for directly specifying element formats. A novice developer still has to grow up to style design.

    A tag refers to sequential elements and therefore cannot include block level elements, e.g.

    Or

    .

    The following parameters can be set for a tag: FACE, SIZE and COLOR. Note that the Netscape browser also allows the use of two additional parameters: POINT-SIZE and WEIGHT, the description of which is omitted.

      FACE

      The FACE parameter is used to specify the type of font in which the user's viewer will display text (if such a font is available on the computer). The value of this parameter is the name of the font, which must exactly match the name of the font that the user has. If no such font is found, this instruction will be ignored and the default font will be used.

      You can specify one or several font names, separating them with commas. This is a very useful property, since different systems may have almost identical fonts with different names. Another important quality is to set preferences for using fonts. The font list is scanned from left to right. If the user's computer does not have the first font in the list, an attempt is made to find the next font, and so on.

      Here is an example of using the FACE parameter:

      Purpose of fonts


      An example of specifying a font name.

      In Fig. Figure 1.4 shows how the Netscape browser displays an example. In the example, the Verdana font is indicated as the preferred font; if it is absent, the Arial font will be used, etc.

    Rice. 1.4. Netscape browser example display

      SIZE

      This parameter is used to specify font sizes in arbitrary units from 1 to 7. The specific font size depends on the viewer you are using. It is generally accepted that a “normal” font size corresponds to a value of 3.

    Default font size settings, as well as the amount of absolute font size change, vary between browsers. In Fig. Figure 1.5 shows the Netscape browser settings window, which sets the default fonts.

    The font size is indicated both as an absolute value (SIZE=2) and as a relative value (SIZE=+1). The latter method is often used in combination with setting the base font size using the .

    Note

    When specifying font sizes, entries like "2" and "+2" (unlike most programming languages, in which the unary "+" sign can be omitted) give fundamentally different results.

    Here's an example that uses different methods for assigning font sizes. An example display is shown in Fig. 1.6.


    Rice. 1.5. Netscape browser font settings window


    Rice. 1.6. Assigning font sizes

    Assigning font sizes

    Font size 1

    Font size 2

    Font size 3

    Font size 4

    Font size 5

    Font size 6

    Font size 7

      COLOR

      This option sets the font color, which can be specified using standard names or in the #RRGGBB format. Here is an example of a document with multi-colored text.

      Choosing a font color

      Green text

      Red text

    Tag

    The tag is used to indicate the default font size, type, and color used in the document. These values ​​are required for the entire document, but can be overridden in necessary places using the tag. After the closing tag, the tag's effect is restored. Default font settings can be overridden multiple times in a document, meaning a tag can appear any number of times in a document.

    Note

    The tag can also appear in a section of the document.

    Note that there is no closing tag for the tag.

    The parameters can be exactly the same as for the tag, namely: FACE, SIZE and COLOR. The purpose and rules for writing parameters are similar.

    Note

    The Netscape browser does not allow the FACE tag parameter.

    Let's give an example of using the tag.

    Assigning font sizes

    Text written in the default font.

    Font size 2.

    Font size 4.

    Text inside a table cell

    Text after table

    The example above overrides the default font size twice. Initially it is 3 (default). Then it is set to 2, then 4. Pay attention to the display of this example (Fig. 1.7). It can be seen that the tag assignment does not work for tables. This is typical for many browsers, although it formally violates the idea of ​​using the tag.


    Rice. 1.7. Displaying example WITH TAG (Netscape browser)

    Formatting an HTML Document

    Dividing into paragraphs

    Any text, be it a school essay, a note in a newspaper or a technical description of a device, has a certain structure. The elements of such a structure are headings, subheadings, tables, paragraphs, etc.

    One of the first rules for drawing up almost any document is to divide its text into separate paragraphs that express a complete thought. HTML documents are no exception to this rule. When creating documents using text editors, breaking into paragraphs is done by entering a newline character. Most editors implement this when you press the key. In HTML documents, newlines do not create a new paragraph.

    HTML assumes that the author of the document knows nothing about the reader's computer. The reader has the right to set any window size and use any of the fonts available to him. This means that where the line hyphen occurs is determined solely by the viewer and the end user's settings. Because line feeds in the original document are ignored, text that looks great in the document's author's editor window may turn into solid, unreadable text in the viewer window.

    You can avoid this trouble by using a special paragraph division tag.

    Before the beginning of each paragraph of text you should place a tag

    Closing tag

    not required. Browsers usually separate paragraphs with a blank line.

    Note

    Browsers typically interpret multiple paragraph tags in a row

    As one. The same applies to the line feed tag
    . Therefore, it is not possible to create multiple empty lines using these tags.

    Tag

    Can be specified with the horizontal alignment parameter ALIGN. Possible parameter values ​​are given in table. 1.4. The default is left alignment.

    Table 1.4. ALIGN parameter values

    ALIGN parameter value

    Action

    LEFT

    Align text to the left edge of the browser window

    CENTER

    Align to the center of the browser window

    RIGHT

    Align to the right edge of the browser window

    JUSTIFY

    Justification (on both sides)

    Note that justification (ALIGN = JUSTIFY) has not been supported by browsers for a long time. Many HTML language descriptions specify only three options for alignment parameter values ​​(LEFT, CENTER, and RIGHT). Currently, all popular browsers can perform width alignment. Some problems with creating justified documents are also discussed in Chapter 8.

    Note

    The lack of justification currently seems surprising. This mode is used very often for printed publications. It is enough to pick up any newspaper or look closely at the paragraphs of this book - they are all aligned in width. However, until recently, justification was not allowed for HTML documents. Just a couple of years ago, no browser had such a mode. Thus, readers who are still using the Netscape browser version 3.x will not be able to see straight lines in the document. You can try to predict what other capabilities browsers will have in the future by comparing the capabilities of powerful text editors and modern browsers. An example of features that have not yet been implemented would be automatic hyphenation, etc.

    Line translation

    When displaying text documents in a browser, the location of line breaks within a paragraph is determined automatically depending on the size of the fonts and the size of the viewing window. Line breaks can only be carried out using word separator characters (for example, spaces). Sometimes in documents you need to set a forced line feed, which is implemented regardless of the browser settings. This is done using the forced line feed tag.
    , which does not have a corresponding closing tag. Enabling a tag
    into the document text will ensure that subsequent text is placed at the beginning of a new line. For example, this approach can be used to create list-type structures without using special list markup tags. Or, for example, this tag cannot be used to display poems, etc.

    Here is an example of using forced line feed (Fig. 1.8):

    Using forced line feed

    Over darkened Petrograd

    November breathed the autumn chill.

    Splashing with a noisy wave

    To the edges of your slender fence,

    Neva was tossing around like a sick person

    Restless in my bed.

    A.S. Pushkin. Bronze Horseman


    Rice. 1.8. Tag
    can be used to force a line feed

    Unlike the paragraph tag

    When using the tag
    an empty string will not be generated.

    Using a tag
    requires caution - it is possible that the browser has already made a line break one or two words before it encountered your tag
    . This happens if the reader's viewer window width is smaller than the same setting of the program with which you tested your document. In this case, it may turn out that only one word remains on a line in the middle of a paragraph, thereby ruining the beauty of the document layout.

    Note

    When using the tag
    To break text around an image or table, you can set the CLEAR parameter to stop text wrapping. You can read about this in chapters 3 and 4.

    Tags u

    There are situations when you need to perform the opposite operation - disable line feed. There is a container tag for this. Text marked with this tag is guaranteed to be on one line, regardless of its length. If the resulting line extends beyond the browser's viewing window, a horizontal scroll bar will appear.

    Note

    To ensure the continuity of text located in table cells, there is a special parameter of the NOWRAP tag . You can learn more about this in Chapter 4.

    By marking up text using the non-breaking line tag, you can get very long lines. To avoid this, you can indicate to the reader's browser the location of a possible line feed, which will be performed only when necessary (the so-called "soft" line feed). This can be done by placing a tag (Word BReak) in the right place in the text, which is the same as the tag
    , does not need a closing tag.

    Note

    The tag is not supported at all by the Netscape browser. The Microsoft Internet Explorer browser recognizes this tag only in text marked with tags.

    Headings inside an HTML document

    Along with the title of the entire document, a Web page can use headings for individual parts of the document. These headings can have six different levels (sizes) and are pieces of text that stand out on the screen when the browser displays the page.

    The tags , , , , and are used to mark up headings. These tags require a corresponding closing tag. Heading number 1 is the largest (top-level heading), and heading number 6 is the smallest. Heading tags are block-level elements, so they cannot be used to mark up individual words of text to increase their size. Heading tags insert a blank line before and after the heading, so no paragraph or line break tags are needed.

    Heading tags can be specified with the horizontal alignment parameter ALIGN. Possible values ​​of the parameter are the same as the alignment parameters of the paragraph tag

    (see table 1.4).

    An example of using headings of different levels with different alignment (Fig. 1.9):

    Heading examples

    Heading size 1

    Heading size 2

    Heading size 3

    Heading size 4

    Heading size 5

    Heading size 6

    Body of the document


    Rice. 1.9. Display headings in different sizes

    Horizontal lines

    Another method of dividing a document into parts is to draw horizontal lines. They visually emphasize the completeness of a particular area of ​​the page. Nowadays, a raised, pressed line is often used to indicate the “volubility” of a document.

    The tag allows you to draw a raised horizontal line in the window of most viewing programs. This tag is not a container, so it does not require a closing tag. A blank line is automatically inserted before and after the line. Tag parameters are presented in table. 1.5.

    Table 1.5. Tag options

    Example:

    This example sets a horizontal line that takes up half the width of the viewport and is positioned in the middle of the window. Note that the alignment options only make sense when the line does not occupy the entire width of the window.

    Note

    The Netscape browser does not allow the COLOR tag parameter.

    Using preformatted text

    As you can see in the sections above, special tags should be used to break up text into paragraphs and force a line break. However, there are times when it is necessary to include text in an HTML document that already has formatting done in the traditional way using newlines, the required number of spaces, tab characters, etc. To solve such problems, a special container tag is provided Defining pre-formatted ( n reformatted) text.

    The text marked with the tag will be displayed as it looks in a regular text editor. A monospaced font will always be used for display. This will give you more control over the document viewer's output, although at the cost of some loss of flexibility.

    One of the options for using this tag is tables built without using special table markup tags. Other important

    The application is to display large blocks of program code (Java, C++, etc.) on the screen, preventing the browser from reformatting them.

    Text inside a container Can contain text-level formatting except the following: , , , , , , , , . It is not acceptable to include block-level formatting elements, such as heading tags, within preformatted text. The paragraph tag, logically, should also not occur inside preformatted text, but if it does, it will implement a new line transition (without creating an empty one).

    Note

    The tag has an optional WIDTH parameter, the purpose of which is to tell the browser the maximum length of a line of preformatted text. Depending on this value, the browser could select the desired font and/or indentation to optimally display the preformatted text. The default value has been suggested to be 80. Other recommended values ​​are 40 and 132. Note that for readers with significant computing experience, these numbers speak volumes. In fact, modern browsers ignore the WIDTH parameter.

    There are several more tags that solve a similar problem. These include the , AND tags. All three of these tags are marked as deprecated in the HTML 4.0 specification. This means that browsers will no longer support them in future versions. It is recommended to use the tag instead of these tags.

    Tag

    A container tag is a block-level element that serves to highlight a fragment of a document. The purpose of this selection is to control the parameters of this fragment, which is usually done by assigning styles. Here's an example:

    (Document fragment)

    In this example, a fragment of an HTML document is framed with tags to set some of its properties. In this case, all text elements of the selected fragment will be displayed in green. An analogue of a text level tag is the element.

    Note that it is not advisable to use direct assignment of style properties of a separate fragment, as is done in the example, in accordance with the concept of separating the structure of the document and its presentation. You should use style sheets, which will be discussed in the second part of the book.

    Tag

    The container tag is designed to horizontally align all elements in the middle of the browser viewport. It is block level and is useful for centering elements such as tables, since they cannot be centered by assignment

    ALIGN=CENTER tag

    .

    Essentially a tag is a short form of the following entry: . Further use of the tag is also undesirable for the reasons noted in the previous section.

    Including comments in a document

    You can include comments in an HTML document that are not visible to the reader. They can consist of any number of lines and must begin with the tag. Anything contained within these tags will not be displayed on the screen when viewing the page.

    In this article, we'll look at the structure of an HTML document and get to know the different parts of a web page.

    HTML Document Structure

    In HTML4, a web page consists of three main parts:

  • Document type declaration (DTD) at the top;
  • An HTML tag that includes the following elements:
  • 1. Head part (Head);
    2. Body:

    Look at the example above. Notice the red and black text? Black indicates the content, and red indicates the tags that make up the elements:


    Document type declaration (1)

    The first line in the example HTML structure is not an element, but a document type declaration (also called a DOCTYPE declaration). It provides information about the version of an HTML document and tells browsers the HTML specification. The correct document declares which version of the language is being used.

    See: DOCTYPE Information

    HTML element (2)

    The entire document is contained within the html element. It is often called the root element and cannot be inside any other element. Used in both HTML and XHTML documents.

    Within an html element, the document is divided into a “head” (head) and a “body” (body).

    Head element (3)

    The head element contains descriptive information about the document itself. What it mentions shouldn't be displayed in the browser, but it does convey some information to it. For example, the title, style sheets used, scripts and other information.

    Meta elements (4)

    The HTML meta site structure element inside head provides metadata information. A meta element can contain different types of information. In the example above, it defines the character encoding used in the document.

    Note: Metadata is information about a document, but not its content.

    Title element (5)

    Head also contains the required title element. According to the HTML specification, every document must include a header. The title specified in this element is shown in the browser tab.

    Body element (7)

    body contains everything we want to display on the web page. This is the part of the HTML document that is displayed in the browser.

    Remember
    • HTML tag - tells the browser how content should be displayed in it.
    • Any HTML document consists of three parts - the document type definition, the head and the body.
    • HTML 5 is defined using , while HTML 4 has three different ways of defining type - Strict , Transitional , and HTML frame structure .
    • is the root element and cannot be placed inside any other element.
    • Elements and are nested inside the element.
    • contains information for the browser
    • contains everything that should be displayed in the browser window.
    • An HTML element is a combination of an opening tag, content, and a closing tag.
    • The Doctype declaration tells the browser which standard it follows.
    • may contain header, style sheets, scripts and metadata.
    • Metadata is information about a document, but not its content.

    The translation of the article “HTML Document Structure – Post #2 – HTML Tutorials” was prepared by the friendly project team.

    Good bad





    

    2024 gtavrl.ru.