HTML- elements

HTML documents are defined by the HTML element.

HTML elements

Element refers to all HTML tags from the tag start (start tag) to the end tag (end tag) of.

Start tag Element content End tag
<p> This is a paragraph </p>
<a href="default.htm" > This is a link </a>
<br />    

Note: The start tag is often called an open-label (opening tag), the end tag is often called the closing tag (closing tag).

HTML element syntax

  • HTML elements start to start the label
  • HTML elements with an end tag termination
  • Content element is the content between the opening and closing tags
  • Some HTML elements have empty content (empty content)
  • Closed empty elements in the start tag (tag beginning to end and end)
  • Most HTML elements can have attributes

Tip: You will learn more about attributes in the next chapter of this tutorial.

Nested HTML elements

Most HTML elements can be nested (can contain other HTML elements).

HTML document consists of nested HTML elements.

HTML document instance

<html>

<body>
<p>This is my first paragraph.</p>
</body>

</html>

The example above contains three HTML elements.

Examples explained HTML

<P> element:

<p>This is my first paragraph.</p>

The <p> element defines a paragraph in the HTML document.

This element has a start tag <p>, and a closing tag </ p>.

Element content is: This is my first paragraph.

<Body> element:

<body>
<p>This is my first paragraph.</p>
</body>

<Body> element defines the body of the HTML document.

This element has a start tag <body>, and an end tag </ body>.

Element content is another HTML element (p element).

<Html> element:

<html>

<body>
<p>This is my first paragraph.</p>
</body>

</html>

<Html> element defines the whole HTML document.

This element has a start tag <html>, and an end tag </ html>.

Element content is another HTML element (body element).

Do not forget the end tag

Even if you forget the end tag, most browsers will correctly display HTML:

<p>This is a paragraph
<p>This is a paragraph

In the example above, most browsers no problem, but do not rely on this practice. Forgetting the end tag can produce unexpected results or errors.

Note: Future versions of HTML allow you to skip end tags.

Empty HTML elements

HTML elements without content are called empty elements. Empty elements are closed in the start tag.

<br> is not closed empty element tag (<br> tag defines a line break).

In XHTML, XML, and future versions of HTML, all elements must be closed.

Adding a slash at the beginning of the label, such as <br />, is the proper way to close empty elements, HTML, XHTML and XML accept this way.

Even <br> are valid in all browsers, but using <br /> actually more long-term protection.

HTML Tip: Use lowercase tags

HTML tags are not case sensitive: <P> is equivalent to <p>. Many sites use uppercase HTML tags.

Guess you like

Origin www.cnblogs.com/fighter007/p/11350791.html