HTML Elements

HTML elements consist of an opening tag, content, and a closing tag. Tags are keywords surrounded by angle brackets, and they come in pairs. The opening tag is used to indicate the beginning of an element, and the closing tag marks the end. The content is what appears on the web page.

Define Elements and tags

Now, let’s break down <tagname></tagname>:

  • <tagname>: This is the opening tag. It marks the beginning of an HTML element. The actual tag name can be anything, depending on the type of content or element you want to represent. For example, it could be <p> for a paragraph, <h1> for a heading, <img> for an image, and so on.
  • </tagname>: This is the closing tag. It marks the end of the HTML element. The tag name inside the closing tag must match the tag name of the opening tag. In HTML, tags are case-insensitive, so <tagname> and </tagName> are considered equivalent.

Graphically, you can represent the structure of the element like this:

<tagname>   Content   </tagname>

Here’s an example using the code <p></p>:

<p>   This is a paragraph.   </p>

In this example, <p> is the opening tag, This is a paragraph. is the content, and </p> is the closing tag.

Nested HTML Elements

Elements can be nested inside each other to create a hierarchy. It’s crucial to maintain proper nesting for the document to be well-structured.


  <p>This is a <strong>strong</strong> paragraph.</p>

In this example, the <strong> element is nested inside the <p> element, which is, in turn, nested inside the <div> element.

Best Practices

Never Skip End Tags

Always include the closing tag for each opening tag. Skipping end tags can lead to unpredictable results.

Example of a good practice

<p>This is a paragraph.</p>

Example of a bad practice

<p>This is a paragraph.

Empty HTML Elements

Some elements have no content and don’t need a closing tag. These are called empty elements and are closed with a trailing slash.


<img src="image.jpg" alt="An image">

HTML is Not Case-Sensitive

HTML is not case-sensitive, meaning you can use uppercase or lowercase letters for tags and attributes.


<P>This is a paragraph.</p>

In summary, HTML elements are the building blocks of web pages, formed using tags. Proper nesting, end tags, code indentation, comments, handling empty elements, and the case insensitivity of HTML are essential aspects to keep in mind for writing clean and maintainable HTML code.