HTML Elements An HTML element is everything from the start tag to the end tag: Start tag Element content End tag <p> This is...
HTML Elements
An HTML element is everything from the start tag to the end tag:Start tag | Element content | End tag |
<p> | This is a paragraph | </p> |
<a href="default.htm" > | This is a link | </a> |
HTML Element Syntax
- An HTML element starts with a start tag
- An HTML element ends with an end tag
- The element content is everything between the start and end tag
- Some HTML elements have empty content
- Some HTML elements have a missing end tag
Nested HTML Elements
Most HTML elements can be nested (can contain other HTML elements).Most HTML documents consist of nested HTML elements.
HTML Document Example
<html> <body> <p>This is my first paragraph</p> </body> </html> |
<p>This is my first paragraph</p> |
The <p> element defines a paragraph in the HTML document:
The element has a start tag <p> and an end tag </p>
The element content is: This is my first paragraph
<body> <p>This is my first paragraph</p> </body> |
The <body> element defines the body of the HTML document
The element has a start tag <body> and an end tag </body>
The element content is another element (a paragraph)
<html> <body> <p>This is my first paragraph</p> </body> </html> |
The <html> element defines the whole HTML document.
The element has a start tag <html> and an end tag </html>
The element content is another element (the body)
Empty HTML Elements
HTML elements without content are called empty elements. Empty elements have no end tag.<br /> is an empty element without a closing tag.
In XHTML, XML, and future versions of HTML, all elements must be closed.
Adding a slash to the start tag, like <br />, is the proper way of closing empty elements, accepted by HTML, XHTML and XML.
Even if <br> works in all browsers, writing <br /> instead is more future proof.
HTML Tip - Lowercase Tags
HTML tags are not case sensitive: <P> means the same as <p>. Plenty of web sites use uppercase HTML tags in their pages.1000sourcecodes use lowercase tags because the World Wide Web Consortium (W3C) recommends lowercase in HTML 4, and demands lowercase tags in newer versions of (X)HTML.