Careeroza
HTML Elements
What is an HTML Element?
An HTML element is defined by a start tag, some content, and an end tag:
<tagname>Content goes here...</tagname>| Start tag | Element content | End tag |
|---|---|---|
<h1> | My First Heading | </h1> |
<p> | My first paragraph. | </p> |
<br> | none | none |
Nested Elements
Example
Elements can contain other elements. Here <body> contains a heading and a paragraph, and the paragraph contains a bold word:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>Nested elements</h1>
<p>This paragraph contains a <b>bold</b> word and an <i>italic</i> one.</p>
</body>
</html>Result
Note: Close elements in the reverse order they were opened: <p><b>text</b></p>, not <p><b>text</p></b>.
Empty Elements
Example
Elements with no content are called empty (or void) elements. They have no end tag. <br> inserts a line break:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<p>This is a<br>paragraph with a line break.</p>
</body>
</html>Result
Other empty elements: <img>, <input>, <hr>, <meta>, <link>.
HTML is Not Case Sensitive
<P> means the same as <p>, but the standard and every style guide use lowercase tags. Also never skip end tags: browsers often guess correctly, but sometimes they do not, and the page breaks in hard-to-find ways.