HTML elements

Home Forums Tech HTML HTML elements

Tagged: 

This topic contains 0 replies, has 1 voice, and was last updated by  MasterMind 1 month, 3 weeks ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #322

    MasterMind
    Keymaster

    An HTML element is a combination of the initial tag, the end tag, and the content.

    Examples of HTML elements:

    Start TagContent of the ElementEnd Tag
    <p>This is a paragraph.</p>
    <b>This is bold text.</b>
    <br />

    Note: most items can also have attributes (attributes will be discussed in detail in the next chapter of this tutorial).

    About the final tag

    The browser will correctly display the HTML element even if you forget to specify the end tag.

    HTML is the language of “forgiving errors”, but there is a more severe version of the language (XHTML), in which skipping the end tag will be considered an error.

    Example

    <p> Paragraph without a closed tag
    <p> Another paragraph without a closed tag

     

    Nested elements

    Most elements can be nested inside each other (that is, another element can be located in the content of one element).

    For example, by enclosing the <i> element in the <b> element, you can make the text bold and italic at the same time.

    In XHTML, elements should always be nested correctly (incorrectly: <i> <b> </ i> </ b>, correctly: <i> <b> </ b> </ i>), in HTML the nested elements are not properly nested are considered an error.

    Example

    <i> <b> This text is italic and bold at the same time. </ b> </ i>

     

    Empty HTML elements

    Elements that can not have content are called empty elements , for example <br>, <hr> are empty elements.

    In XHTML, empty elements must have a closing tag (<br /> , <hr / >), in the absence of closing HTML tag is not considered an error, and the browser will correctly display these elements.

    In which register to write tags?

    HTML is not case sensitive, which means that the <b> tag will be interpreted by the browser as well as the <B> tag, in XHTML tags can be written only in the lower layout.

    Despite the fact that HTML does not insist on strict syntax, we recommend in advance to work out certain rules for writing code (for example, if you write tags in the lower layout, then do so always).

    Code is not following any rules unpleasant to read and difficult to understand.

    Compare:

    <! - 1. Code written in "free style" -> <HR> <P ID = par1 > This is the first paragraph
     <br /> <i> <p> This is the second paragraph </ I> 
    
    <HR> 
    <! - 2. The code following the XHTML rules -> 
    <hr /> 
    <p id = "par1" > This is the first paragraph </ p> 
    <br /> 
    <p> <i> This is the second paragraph </ i> </ p >
     <hr />
    

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.