HTML PROGRAMMING:HTML – Elements

Mastering html – elements concepts and implementation.

In HTML, an element is more than just a tag. An HTML element usually consists of three main parts:

  • A start tag (opening tag)
  • Some content (text or other elements)
  • An end tag (closing tag)

Together, these parts tell the browser what the content is and how it should be treated.

Element vs tag

Many beginners confuse tags and elements, but they are not the same thing.

  • Tag: The markup written inside angle brackets, such as <p> or </p>.
  • Element: The complete structure made up of the opening tag, content, and closing tag.

Example:

  • <p>This is a paragraph</p>
  • <p> → opening tag
  • </p> → closing tag
  • "This is a paragraph" → content
  • All of this together forms one paragraph element.

Nested elements

HTML allows elements to be placed inside other elements. This is called nesting.

Example:

  • <p>This is <b>very</b> important.</p>

In this case:

  • The <p> element contains text and a <b> element.
  • The <b> element is nested inside the <p> element.

Nesting is extremely common in real websites and is how complex page structures are built.

Rules for nesting

  • Always close inner elements before closing outer elements.
  • Do not overlap tags.

Incorrect nesting:

  • <b><i>text</b></i>

Correct nesting:

  • <b><i>text</i></b>

Incorrect nesting can confuse browsers and screen readers.

Block-level vs inline elements (basic idea)

At a high level, HTML elements fall into two categories:

  • Block-level elements (like <div>, <p>, <h1>)
  • Start on a new line
  • Take up the full available width
  • Inline elements (like <span>, <b>, <i>, <a>)
  • Stay within the same line
  • Take up only as much width as needed

You will often place inline elements inside block-level elements to add emphasis or links within text.

Empty (void) elements

Some HTML elements do not contain any content and therefore do not have a closing tag. These are called empty or void elements.

Common examples:

  • <br> – line break
  • <hr> – horizontal rule
  • <img> – image

These elements only use attributes inside their opening tag.

Suggested image prompt

"Diagram showing an HTML element broken into parts: opening tag, content, closing tag, plus another diagram showing nested elements inside each other like boxes."

Interview-style questions from this topic

  1. What is the difference between an HTML tag and an HTML element?
  2. What does nesting mean in HTML?
  3. Give an example of correct and incorrect nesting.
  4. What are block-level and inline elements?
  5. What are empty (void) elements? Give examples.
  6. Why is proper nesting important in HTML?

Hands-on Examples

Nested Elements Example

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

In this example, the <i> and <u> elements are nested inside <h1> and <p>. The browser first understands the outer element (heading or paragraph) and then applies additional meaning or styling from the inner elements. This shows how HTML elements work together to form rich content.