HTML Elements
HTML Elements
An overview of HTML elements, including start tags, end tags, empty elements, and nesting.
An HTML element is made of a start tag, the element’s content, and usually an end tag. The element includes everything from the opening tag to the closing tag.
Element Structure
Most HTML elements follow a common structure.
<tagname>Content goes here...</tagname>
Examples
<h1>Welcome</h1>
<p>This is a paragraph.</p>
Start Tag and End Tag
The start tag opens the element. The end tag closes it and uses a forward slash.
<strong>Important</strong>
<em>Emphasis</em>
Empty Elements
Some elements have no content and no closing tag. These are called empty (or void) elements.
<img src="photo.jpg" alt="A photo">
Example with a line break
First line<br>
Second line
Nesting Elements
Elements can contain other elements. Correct nesting keeps the document structure predictable.
<p>A paragraph with <strong>bold text</strong> inside.</p>
Example Document
A basic HTML document is built from nested elements.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<p>A short paragraph.</p>
</body>
</html>
Closing Tags
Some elements may appear to work without closing tags in certain browsers, but relying on this can cause unexpected results.
<p>First paragraph</p>
<p>Second paragraph</p>
Case Sensitivity
HTML tag names are not case-sensitive, but lowercase is the common convention and improves readability.
<p>Lowercase</p>
<P>Also valid, but usually avoided</P>