Contacts

HTML5 syntax. PHP Syntax HTML Tag Syntax

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 (like 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 example:

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 portions of the document text, not entire areas. An inline element does not cause a new line 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.

HTML5 brings us back to a decade-old style of leaving some tags unclosed, writing values ​​without quotes, and optionally typing tags in uppercase or lowercase. This freedom does not mean that any rules should be ignored, you should still observe the correct nesting of tags and insert mandatory elements. Breaking away from the rigid XHTML syntax allows you to focus on the content of the site, and not on the observance of empty formalities, most of which are annoying because of their inconsequential value and uselessness.

HTML elements

The basic building block of a web page is an element. They can be divided according to different criteria, for example, by type or purpose.

Elements by type

Empty elements

These include elements that do not have a closing tag: , ,
, , , ,


, , , , , , , , , .

Unprocessed text elements

Designed to output scripts or styles that have a syntax other than HTML:

Если после элемента следует

  • Если после элемента следует
    или
    .
    Если после элемента следует
    ,
    или он последний у родителя.

    Если после элемента следует
    ,
    ,