HTML Elements


🔹 What is an HTML Element?

An HTML element is everything from the start tag to the end tag, including its content.

👉 Basic Syntax:

<tagname>Content goes here</tagname>

Example:

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

🔹 Components of an HTML Element

Part Description
Start Tag <p> – Opens the element
Content This is a paragraph.
End Tag </p> – Closes the element
Full Element <p>This is a paragraph.</p>

🔹 Nested HTML Elements

You can place one element inside another — this is called nesting.

<p>This is a <strong>bold</strong> word.</p>

📌 Always close nested tags in the reverse order they were opened.


🔹 Empty Elements

Some elements do not have content or closing tags.

Examples:

<br>     <!-- Line break -->
<hr>     <!-- Horizontal rule -->
<img src="pic.jpg" alt="Photo">  <!-- Image -->

🔹 Block vs Inline Elements

Type Description Examples
Block Starts on a new line, takes full width <div>, <p>, <h1>
Inline Stays in line with text, takes only necessary space <span>, <a>, <img>

Example:

<p>This is <span>inline</span> text.</p>

🔹 Example: Combining Multiple Elements

<!DOCTYPE html>
<html>
<head>
  <title>HTML Elements Example</title>
</head>
<body>
  <h1>Welcome!</h1>
  <p>This is a paragraph with <a href="#">a link</a>.</p>
  <hr>
  <img src="example.jpg" alt="Example Image">
</body>
</html>

🔹 Notes:

  • HTML elements can have attributes (like href, src, alt, etc.)

  • Be careful with proper nesting

  • Indentation improves readability


Practice Questions

Q1. Create a paragraph element using <p> with any text.

Q2. Write a heading using <h2> with the text "My Page".

Q3. Create a nested element with <strong> inside a <p>.

Q4. Insert a horizontal line using the <hr> tag.

Q5. Add a line break using the <br> tag between two sentences.

Q6. Create an anchor tag <a> with link text "Click here".

Q7. Add an image element <img> with a sample src and alt.

Q8. Identify 2 block elements and add them to an HTML file.

Q9. Write an inline element example using the <span> tag.

Q10. Create a full HTML page with at least 5 different elements.


Go Back Top