Slide 1
Slide 2
Slide 3

Nested elements in HTML5 (HTML-V11)

No Comments

Lesson 4: Elements & Attributes

HTML elements are the basic building blocks for creating web pages. They are made up of an opening tag, content, and an ending tag.

An HTML element is a basic component of an HTML document. It can hold data to display on a web page, such as text, images, or links, and sometimes it holds nothing at all. An HTML element has an opening tag, content, and a closing tag, and the opening tag can also contain attributes.

An HTML element consists of:

  • Opening Tag: Marks the starting point of the element and can contain multiple attributes.
  • Content: The text part, which includes the information to be displayed or processed inside the element.
  • Closing Tag: Marks the end point of the element. (Some elements do not need a closing tag.)

An HTML document is made up of a tree of HTML elements. This tree defines the content and layout of the web page, such as how the content is formatted and what is shown in each part of the page.

 Some examples of HTML elements are as follows:

The table below shows the different parts (opening tag, content, and closing tag) of the HTML elements used in the example above:

Opening Tag Content Closing Tag
<p> This is paragraph content. </p>
<h1> This is heading content. </h1>
<div> This is division content. </div>

So <p>...</p> is one HTML element, and <h1>...</h1> is another HTML element.

1. HTML Element Structure

The image below shows the structure of an element, such as how to write an HTML element with an opening tag and a closing tag.

❖ What is the difference between an element and a tag?

This is a point that confuses most beginners. Here is an easy way to think about it:

  • An HTML Tag is only the opening part <p> or the closing part </p>. It is an instruction.
  • An HTML Element is the whole thing: the opening tag, the content inside, and the closing tag.
  • Think of it like a sandwich. The two slices of bread are the Tags, and the whole sandwich with everything inside is the Element.

2. Understanding Nested Elements

HTML allows elements to be placed inside one another (nesting of elements). Nested elements are created by placing one or more HTML elements inside another HTML element. The outermost element can be considered the parent element, and the other elements inside it are the child elements. A child element sits inside its parent element. We can nest elements across multiple levels (multiple levels of nesting), but we need to follow a few guidelines:

  • Every opening tag must have a matching closing tag.
  • The closing tag of the parent element must come after the closing tag of the child element.
  • Nested elements must be valid HTML elements.

Source Code:

Copied!
<!DOCTYPE html>
<html>
<head>
   <title>Nested Elements Example</title>
</head>
<body>
   <h1>This is <i>italic</i> heading</h1>
   <p>This is <u>underlined</u> paragraph</p>
</body>
</html>

Result:


Watch the video:


Ebook: https://softkhpc.blogspot.com/2026/11/html-tutorial-beginners.html

back to top