HTML5 brings us back to the style of a decade ago, when it was common practice to leave some tags unclosed, write values ​​without quotes, and optionally type tags in upper or lower case. This freedom does not mean that any rules should be ignored; correct nesting of tags and insertion of required elements should still be observed. Moving away from the rigid syntax of XHTML allows you to focus on the content of the site, and not on complying with empty formalities, most of which cause irritation due to their insignificant meaning and unnecessaryness.

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.

Items 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: , .

RCDATA

These elements can contain any text or special characters, with the exception of non-standard special characters called ampersands, for example: or &T. This group of elements includes and.

Foreign elements

Elements related to MathML or SVG.

Regular elements

All other elements that are not included in the previous groups.

Elements by purpose

Root element

Element.

Document metadata

, as well as the elements that are located inside it.

Scripts

Scripts allow you to add interactivity to a web page; this group includes elements that control scripts.

Structural elements

Elements that control the main sections of a web page, such as , , , , etc.

Content Grouping

Elements framing text, lists, images.

Text

Elements that change the appearance of the text, for example, making it bold or italic, as well as highlighting the text by meaning - abbreviation, quote, variable, code, etc.

Review

Elements and showing edits in a document.

Embedded Content

Elements inserted onto the page in the form of different objects - images, video, audio, etc.

Tabular data

Elements for creating and managing the appearance of tables.

Forms

Forms are one of the important elements of any website and are designed for the exchange of data between the user and the server. This group includes elements for creating a form and its fields.

Interactive elements

Special widgets with which the user can obtain additional information or control.

Links

Elements And .

Such grouping is conditional and can take on a different form, because the same elements can belong to different groups.

Tags

Tags are used to indicate the beginning and end of an element. Inside tags there can be attributes with their own values ​​that expand the capabilities of the tags, as well as the content (Fig. 1).

Rice. 1. Tag with href attribute

The closing tag is similar to the opening tag, but contains a slash (/) inside angle brackets.

Empty elements have no closing tag and no content (Figure 2).

Rice. 2. Empty tag

Tag attributes expand the capabilities of the tags themselves and allow you to flexibly manage various settings for displaying web page elements. The total number of attributes is quite large, but their values, as a rule, can be grouped into different types, for example, specifying color, size, address, etc. For example, an element adds an image to the web page, and we indicate the address of the graphic file through the src attribute.

Doctype

is intended to indicate the type of the current document - DTD (document type definition, description of the document type) so that the browser understands which version of HTML it is dealing with. If the doctype is not specified, browsers go into compatibility mode, in which many HTML5 features do not work, and errors occur with document display.
The doctype is not case sensitive and contains only two words:

This is the key element and is usually located in the first line of code.

Comments

Some text can be hidden from being shown in the browser by making it a comment. Although this text will not be seen by the user, it will still be transmitted in the document, so if you look at the source code, you can discover hidden notes.

Comments are needed to make your own entries in the code that do not affect the appearance of the page. They start with the tag. Anything between these tags will not be displayed on the web page.

Optional Tags

If a tag is not listed, it does not mean that it is not represented at all. There are certain rules that allow you not to write some tags. In table 1 shows tags that can be omitted and the condition under which this occurs.

Table 1. Optional tags Tag Condition
If there are other elements inside.
If empty and also contains something other than a space or a comment.
If an element is followed by
  • If an element is followed by or .
    If the element is followed by , or it is the last one of the parent.

    If the element is followed by , , , , , , , , , , ,..., , , , , , , ,

    , , ,

    ,
      .
    and does not come before , or which have an omitted closing tag.or he is the last one with the parent.
    If an element is followed by or .
    If an element is followed by or .
    If the element is followed by or is the last element of the parent.
    If the element is followed by , or it is the last one of the parent.
    If the . comes first inside and does not come before another element.
    If an element is followed by or .
    If the first one inside is
    If the element is followed by or or it is the last element of the parent.
    If the element is followed by or is the last element of the parent.
    If an element is followed by
    If an element is followed by or or he is the last one with the parent.
    If an element is followed by or or he is the last one with the parent.

    If the opening tag contains one or more attributes, then the tag must be specified.

    Due to the fact that many tags may not be specified, because... they are implied by default, any document is reduced to the following parts.

  • An optional byte order mark (BOM).
  • .
  • .
  • You can insert any number of spaces or comments before and after the doctype. Thus, the doctype does not have to be on the first line of code.

    Example 1 shows the minimal HTML code to display a traditional greeting.

    Example 1: Minimal HTML

    HTML5 IE Cr Op Sa Fx

    Hello World!

    A byte order mark consists of a U+FEFF character code at the beginning of the document, where it is used to determine the encoding. It is recommended to remove this symbol, since its presence leads to errors in displaying the document in some browsers. To do this, you can use the Notepad++ editor, in the “Encodings” menu, select “Encode in UTF-8 (without BOM)” (Fig. 3).

    Rice. 3. Select encoding

    useful links
    • More about byte order mark
      http://unicode.org/faq/utf_bom.html#bom1
    • Notepad++ editor

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


    DOCTYPE Description
    HTML5
    For all documents.
    HTML 4.01
    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
    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 - standard language Web document markup.

    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, the align tag and 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 Requirements Cannot Required
    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 occurs 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 a 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

    in red.

    Compliance of HTML code with the declared standard is called validity, and checking for this compliance is called 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

    Some of the text needed to be highlighted in red.

    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 search engines. Even one missing tag

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

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



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

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

    All HTML elements are divided into five types:

    • empty elements - , ,
      , , , , , , , , , , , , ;
    • elements with unformatted text - , ;
    • elements that display unformatted text - , ;
    • elements from another namespace - MathML and SVG;
    • ordinary elements - all other elements.

    The table provides a complete list of elements supported by HTML4 and HTML5. Experimental and legacy tags are excluded. Elements added to the HTML5 specification are highlighted in teal.

    Complete list of HTML elements Table 1. HTML elements Tag Description
    Used to add comments.
    Declares the document type and provides basic information to the browser - its language and version.
    Creates hypertext links.
    Identifies text as an abbreviation or acronym. Explanatory text is specified using the title attribute.
    Specifies the contact information of the author/owner of the document or article. Displayed in italics in the browser.
    It is a hyperlink with text corresponding to a specific area on an image map or an active area within an image map. Always nested inside a tag.
    A section of content that forms an independent part of a document or website, such as a magazine article, blog post, comment.
    Represents page content that is indirectly related to the main content of the page/site.
    Loads audio content into a web page.
    Sets a passage of text to be bold without adding emphasis or importance to the highlighted text.
    Specifies the base address (URL) from which all relative addresses are calculated. This will help avoid problems when moving the page to another location, since all links will work as before.
    Isolates a passage of text written in a language in which the text is read from right to left from the rest of the text.
    Displays text in the direction specified by the dir attribute, overriding the current text direction.
    Highlights text as a quote, used to describe large quotes.
    Represents the body of the document (content that is not part of the document's metadata).

    Wrap text to a new line.
    Creates an interactive button. You can place content inside the tag - text or image.
    Canvas container for dynamically displaying images such as simple images, charts, graphs, etc. The JavaScript scripting language is used for drawing.
    Adds a caption to the table. Inserted immediately after the tag .
    Used to indicate the source of a citation. Displayed in italics.
    Represents a piece of program code, displayed in a monospace font family.
    Selects one or more table columns for formatting that do not contain the same type of information.
    Creates a structural group of columns that identifies many logically homogeneous cells.
    The element is used to associate the value of the value attribute, which is in a machine-readable format and can be processed by a computer, with the content of the tag.
    Container element for a drop-down list element. Variant values ​​are placed in elements.
    Used to describe a term from a tag.
    Marks text as deleted by striking it out.
    Creates an interactive widget that the user can open or close. Represents a container for content, the visible title of the widget is placed in the tag.
    Identifies a word as a term by putting it in italics. The text that follows should contain a definition of this term.
    An interactive element with which the user interacts to complete a task, such as a dialog box, inspector, or window. Without the open attribute, it is not visible to the user.
    A container tag for sections of an HTML document. Used to group block elements for formatting with styles.
    A container tag containing a term and its description.
    Used to specify a term.
    Highlights important passages of text by displaying them in italics.
    A container tag for embedding external interactive content or a plugin.
    Groups related elements in a form by drawing a box around them.
    Title/caption for the element.
    A self-contained container tag for content such as illustrations, diagrams, photographs, code examples, usually with a caption.
    Defines the ending area (footer) of a document or section.
    A form for collecting and sending information from users to the server. Doesn't work without the action attribute.
    Create six levels of headings for related sections.
    A container element for HTML document metadata, such as , , , , .
    Section for introductory information of a site or a group of navigation links. May contain one or more headings, logo, information about the author.
    A horizontal line for thematic division of paragraphs.
    The root element of an HTML document. Tells the browser that this is an HTML document. It is a container for all other html elements.
    Italics a passage of text without giving it additional emphasis.
    Creates an inline frame by loading another document into the current HTML document.
    Embeds images in an HTML document using the src attribute, whose value is the URL of the embedded image.
    Creates rich form fields in which the user can enter data.
    Highlights text with underlining. Used to highlight changes made to a document.
    Selects text to be entered by the user using the keyboard in a monospace font.
    Used to store additional information about the page. This information is used by browsers to process the page, and by search engines to index it. There can be several tags in a block, since depending on the attributes used they carry different information.
    Indicator of measurement in a given range.
    A section of a document containing navigation links for the site.
    Defines a section that does not support scripting.
    Container for embedding multimedia (e.g. audio, video, Java applets, ActiveX, PDF and Flash). You can also insert another web page into the current HTML document. The tag is used to pass the parameters of the plugin.
    Ordered numbered list. Numbering can be numeric or alphabetical.
    A container with a title for a group of elements.
    Specifies an option/option to select from the , or , drop-down list.
    Field for displaying the result of a calculation calculated using the script.

    Paragraphs in the text.
    Defines parameters for plugins embedded using the element.
    A container element containing one element and zero or more elements. By itself it does not display anything. Allows the browser to select the most appropriate image.
    Outputs text without formatting, preserving spaces and text breaks. Can be used to display computer code, email messages, etc.
    An indicator of the completion of a task of any kind.
    Defines a short quotation.
    Container for East Asian symbols and their decoding.
    Defines its nested text as the base component of the annotation.
    Adds a brief description above or below the characters contained in the element, displayed in a smaller font.
    Marks embedded text as additional annotation.
    Displays alternative text if the browser does not support the element.
    Displays text that is not current with a strikethrough.
    Used to display text representing the result of program code or script execution, as well as system messages. Displayed in monospace font.
    Used to define a client-side script (usually JavaScript). Contains either script text or points to an external script file using the src attribute.
    Defines a logical area (section) of a page, usually with a header.
    A control element that allows you to select values ​​from a proposed set. Variant values ​​are placed in .
    Displays text in a smaller font size.
    Specifies the location and type of alternative media resources for the , , .
    Container for inline elements. Can be used to format passages of text, such as highlighting individual words.
    Places emphasis in the text, highlighting it in bold.
    Includes embeddable style sheets.
    Specifies subscript writing of symbols, for example, element index in chemical formulas.
    Creates a visible title for the tag. Displayed with a filled triangle, clicking on it allows you to view the title details.
    Specifies the superscript spelling of characters.
    Tag for creating a table.
    Defines the body of the table.
    Creates a table cell.
    Used to declare HTML code fragments that can be cloned and inserted into a document by a script. The content of a tag is not a child of it.
    Creates large text input fields.
    Defines the table footer.
    Creates a table cell title.
    Defines the table title.
    Defines date/time.
    The title of an HTML document that appears at the top of the browser's title bar. May also appear in search results, so this should be taken into account when providing a title.
    Creates a table row.
    Adds subtitles for elements and .
    Highlights a passage of text by underlining, without additional emphasis.
    Creates a bulleted list.
    Highlights variables from programs by displaying them in italics.
    Adds video files to the page. Supports 3 video formats: MP4, WebM, Ogg.
    Indicates to the browser where a long line might break.
    Cheat sheet with tags

    For ease of use, I grouped the tags into thematic sections, adding display property values ​​for each tag. To go to the table, click on the picture.

    Alexander Kichatov

    How PHP scripts work

    Surely you are familiar with the principle of operation of radio-controlled cars. You press forward - the car moves, you press to the left - the car changes the direction of the wheels.

    PHP works exactly the same. You write commands one after another, and PHP executes them sequentially.

    What is a PHP script

    A PHP script is a regular text file with a .php extension. Exactly the same as html and css.

    But there is one important difference:

    Scripts are launched only through http requests in the browser. This means that to run the script.php script, you need to write site.ru/script.php in the browser address bar

    If the script doesn't work, check the current URL. If there is something like file:///D:/openserver/domains/site.ru/script.php, this means that you are not trying to go to the site page, but to open the PHP file itself in the browser. It is not right.

    Web servers are most often configured so that when you access the main page (for example site.ru), the index.php or index.html file located at the root of the site is automatically launched.

    Create a file called index.php in the root folder of the site and open it in your text editor. If there is an index.html file, it must be deleted.

    If you don’t have a text editor yet, I recommend the lightweight and free Notepad++, it is much more convenient than the notepad built into Windows.

    Be sure to follow the coding of the scripts. The encoding should be either UTF-8 without BOM (if such is available in your editor), or simply UTF-8.

    Printing numbers and strings in PHP

    PHP commands are written between tags, for example:

    The echo command is responsible for displaying information on the screen. After the operator, the value to be output is indicated.

    To display text, it must be specified in single or double quotes:

    Commands in PHP are separated by semicolons. For ease of reading, each command is usually written with new line:

    Result in browser:

    This is PHP code.

    Outputting HTML code in PHP

    HTML code can be mixed with PHP commands:

    You can also insert the HTML code into a PHP string:

    Result in browser:

    Elephant Napoleon

    We can combine PHP code and HTML tags in any way we want:

    Functions in PHP

    A function is a command that performs some action, such as calculations, file management, etc.

    Defining a function is simple - it has parentheses after its name:

    The phpinfo() function displays information about the current PHP settings.

    Some functions expect some value to be passed to them. For example, the rounding function ceil() expects a number to round:

    The ceil() function receives the value 91.5 we passed, processes it (rounds it to 92) and returns the result. And the echo command receives the value returned by the function and displays it on the screen. The result of this script will be 92.

    Necessity of Closing Tag in PHP

    If there is no HTML or any other output to the screen after the PHP commands, then we can omit the closing ?> tag:

    In addition, we can replace the tag

    Using a tag