Basic rules of the HTML language. HTML markup language, syntax Basic rules of the HTML language

HTML Syntax

Rice. 1.6. Displaying a simple HTML page in a web browser

Basic Rules of the HTML Language

HTML tag names are not case sensitive, and in XHTML small and large letters are considered different, and tag names must be written in small letters.

Elements can include text and sub-elements (as, for example, the html element contains head and body sub-elements in the example above). Elements must be correctly nested within each other.

Sub-elements included in an element must end before the element's closing gag. For example, the following entry is incorrect: <а>

Correctly, this fragment should look like this:

This is bold and italic text

In XHTML, if an element does not include text and subelements (an empty element), it must still have an opening and closing tag. For example, the br element has no content and causes a line break (text continues on a new line). However, according to the rules, it must be written as follows:

or abbreviated
. The element should be written in the same way


- Draw a horizontal line.

Element opening tags can have attributes, which refine the behavior of the element and set additional values. Almost every tag has a large number of optional parameters. Further, only the main attributes of tags will be considered.

Many attributes in HTML are common to all elements, but some are specific to a given element or elements. They all take the form:

attribute_name="value"

For instance:

Fundamentals of Hypertext Markup Language"

In this example, the div element (a section of an HTML page that allows documents to be divided into logical blocks) has an id attribute set to mySection. The div element contains an h1 element (the first, or most important, level heading), which in turn contains some text. Attribute values ​​must be enclosed in single or double quotes.

The tag and attribute names and their possible values ​​are determined by the HTML language specification, and you cannot create your own tags or attributes.

All elements can have id and class attributes, the values ​​of which are used to identify specific elements (id) or a group of elements (class). These attributes are heavily used in document scripts and CSS descriptions of document styles.

There are two main categories of elements in HTML: block and string

  • Block elements usually inform about the structure of the document. Such elements start on a new line, breaking away from what was before it. Examples of block elements are paragraphs, list items, headings and tables, div containers.
  • String elements are contained within block-level structural elements and cover only parts of the text of the document, not entire areas. An inline element does not cause a newline to appear in the document, as they are elements that appear in a paragraph of text. Examples of string elements are links, highlighted words or phrases, span containers.

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

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

All HTML elements are divided into five types:

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

Top