# Understanding HTML Tags and Elements

HTML Stands for Hyper Text Markup Language.use for creating web pages. It is describe the structure of a web page. it is consist a series of a elements.These elements are tell the browser to how to display the content.

```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <p>This is my First Paragraph</p>
</body>
</html>
```

Example Explanation:

1. The `<!DOCTYPE>` declaration defines that this document is an HTML document.
2. `<html>` tag is a root element of an HTML Page.
3. `<head>` Tag contain meta information about HTML Page Such as title character encoding, viewport settings,stylesheets and scripts.defer execute the external script after parsing the HTML.
4. The `<body>` tag is one of the most impoertant element in HTML because it contains main content of webpages that user sees and interact with it .Lists ,Tables ,Containers,Semantic elements are the common elements which i write inside the body tag.

## HTML DOM Tree Structure

When we combine html elements such as `<html>` `<head> <title>` `<body> <h1>` and `<p>` they form a tree like structure called a DOM Tree.A Tree represent the relationship between HTML elements such as parent child and sibling relationship.

Consider this HTML Code:

```plaintext
<!DOCTYPE html>
<html lang="en">
<head>
    <title>My Website</title>
</head>
<body>
    <h1>Welcome to My Website</h1>
    <p>I am learning HTML.</p>
    <div>
        <h2>About Me</h2>
        <p>I am a web developer.</p>
    </div>
</body>
</html>
```

The Browser Parse this HTML and creates a DOM Tree in memory.

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/f6981929-bee4-4fd8-8962-c3f752993835.png align="center")

Noticed that the `<html>` element has two children `<head>` and `<body>`.The `<body>` element has three children `<h1>` `<p>` `<div>`.The Actual Dom also include text nodes, a document type node,a other possible type node.The above diagram focuses on HTML Elements to make a hierarchy easy to understand.

## Understand Parent Child and Sibling Relationships

1. A Parent is an element that directly contain another element.
2. A Child element directly nested inside an another element.
3. Siblings is an element that share same Parent.

## Ancestor and Descendanr Relationship

These relationships go beyond aprent child relations.

`<body> <div> <section> <p>Hello World</p> </section> </div> </body>`

For the `<p>` element `<section>` is a parent element and `<div>` is a grandparent element.`<body>` `<section>` `<div>` are its ancestors.for the `<body>` element `<div>` `<section>` `<p>` are descendant.

## The Browser Process HTML in Stages

1. HTML source code

Browser receives HTML markup

2. HTML parsing

Browser recognizes tags, attributes, and text

3. DOM construction

Browser creates nodes and connects them

4. Rendering

Browser combines DOM, CSS, and layout information to display the page.

What is an HTML Tag?

A HTML Tag is a piece of markup Written inside angle bracket (&lt; >) that tells the browser how to interpret the different parts of HTML document.

HTML Tags are used to define elements such as headings, paragraphs, images,links,tabl;es and forms.

Basic Example of an HTML Tag

1. `<h1> Hello World </h1>`
2. `<h1>` is the Opening Tag.
3. `</h1>` is the closing Tag.
4. `Hello World` is the Content.

## Types of HTML Tags

### 1\. Paired Tags

These usually have an opening tag and closing tag and content between them.

```plaintext
<p> This is a paragraph. </p>
<h1> This is a heading. </h1>
```

Example:`<p> <h1>` `<div>` etc.

### 2\. Void Tags

These elements do not have closng tags because they can not contain child content.

```plaintext
<br>
<hr>
<img src="photo.jpg" alt="A photo">
<input type="text">
```

Example:`<br>` `<hr>` `<img>` `<input>` etc.

## What is a HTML Element

An HTML element is a complete component of HTML document , usually consisiting of an opening tag , content and closing tag.

Example of HTML Element

```plaintext
<p> Hello World! </p>
```

1. `<p>` tells the browser that a paragraph element begins.

2) `Hello World!` is the text inside the paragraph.
3) `</p>` makes the end of paragraph element.

Together Opening Tag. Content and Closing Tag Form a paragraph Element.

**Difference between HTML Tag and HTML Element.**

| HTML tag | HTML element |
| --- | --- |
| A tag is markup written inside angle brackets. | An element is a complete component in the document. |
| Example: `<h1>` | Example: `<h1>Welcome</h1>` |
| Opening and closing tags are individual tags. | The element includes its tags and content. |

## What is a Block Level Element

A Blocl Level Element normally starts on a new line and next block level element appears below it.

Example:

```plaintext
<h1> Hello World </h1>
<p> This is a paragraph. </p>
<div> This is a div element. </div>
```

The Browser Display these elements onn separate lines by default

Browser preview

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/d6534413-a865-486a-a0a8-7115e528e266.png align="center")

**Common Block Elements**

1. `<div>` generic container
2. `<p>` paragraph
3. `<h1>` to `<h6>` headings
4. `<section>` section of a document
5. `<article>` self-contained content
6. `<header>` introductory content
7. `<footer>` footer content
8. `<ul>` and `<ol>` lists

**Important characteristics**

1. They normally begins on a new line.
2. They generally occupy the available width by default.
3. You can control their height, width, margin, padding by using CSS.
4. They can Contain other elements, subject to HTML nesting rules.

## What is inline element

These elements normally stays on the same line as surrounding text and takes up only the space it needs.

**Example:**

```plaintext
<p>
    I am learning
    <strong>HTML</strong>
    and <em>CSS</em>.
</p>
```

Here, `<strong>` and `<em>` are inline elements by default. They do not force the text on to new line.

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/81b89eb6-d962-46ff-b9f1-d3c34a2c8aa9.png align="center")

**Common inline elements**

1. `<span>` generic inline container
2. `<a>` hyperlink
3. `<strong>` important text
4. `<em>` emphasized text
5. `<br>` stylistically bold text
6. `<i>` alternate voice or mood, often displayed in italics
7. `<code>` inline code
8. `<label>` label for form control.

**Important characteristics**

1. They normally do not start a new line.
2. Their width usually depend on their content.
3. The `width` and `height` properties generally do not affect ordinary non-replaced inline elements.
4. Vertical margins and padding do not behave like they do on block elements.

**Diiference between Block elements and inline elements**

| Feature | Block element | Inline element |
| --- | --- | --- |
| New line | Normally starts on a new line | Normally stays on the current line |
| Default width | Usually available container width | Usually content width |
| Width and height | Generally configurable | Usually do not apply to ordinary inline elements |
| Examples | `<div>`, `<p>`, `<h1>` | `<span>`, `<a>`, `<strong>` |
| Typical use | Structuring page sections | Styling or marking text within a line |

## What is inline-block element

An element with `display: inline-block` combines the features of inline and block elements.

- Inline: It can sit alongside other elements on the same line.
- Block: You can set its width, height, margin, and padding.

```plaintext
<div style="display: inline-block; width: 150px; height: 80px; background: lightblue;">
    Box 1
</div>

<div style="display: inline-block; width: 150px; height: 80px; background: lightgreen;">
    Box 2
</div>
```

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/f15921fb-3d29-4683-929e-776128df55b1.png align="center")

Both boxes appear on the same line when enough space is available, and each has a specified width and height.

## Commonly used HTML Tags

1. `<h1>` Defines a top level heading

`<h1>Heading 1</h1>`

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/f34d8139-0a10-4dc2-af14-8c30a120aa9b.png align="center")

2. `<h2>` Defines a Second Level Heading

**Code:**

`<h2>Heading 2</h2>`

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/31c97649-6789-4f44-b491-dbc7e4c1728c.png align="center")

3. `<h3>` Defines a Third Level Heading

**Code:**

`<h3>Heading 3</h3>`

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/9c315688-613d-440e-a5f6-c471570c4e3e.png align="center")

4. `<h4>` Defines a Fourth Level Heading

**Code:**

`<h4>Heading 4</h4>`

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/a10be86a-62a9-4db6-9790-0b74b409c1d0.png align="center")

5. `<h5>` Defines a Fifth Level of Heading

**Code:**

`<h5>Heading 5</h5>`

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/d21f44e3-dfe3-461f-af25-bbeee94171d7.png align="center")

6. &lt;h6> Defines a sixth Level of Heading

Code:

`<h6>Heading 6</h6>`

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/caee96ea-86b8-4b76-9c02-bfbfdb3257c5.png align="center")

**All Heading Tags**

**Code:**

```html
    <h1>Heading 1</h1>
    <h2>Heading 2</h2>
    <h3>Heading 3</h3>
    <h4>Heading 4</h4>
    <h5>Heading 5</h5>
    <h6>Heading 6</h6>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/4054feed-ec42-4652-8dbf-d10dc5d16cd0.png align="center")

7. `<p>` Defines a Paragraph of a text

**Code:**

`<p>I am Learning a HTML</p>`

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/c714a467-50d6-401c-87a3-f3d06f3f51a0.png align="center")

8. `<div>` Creates a generic block container for grouping elements

**Code:**

```html
 <div>
        <h2>Product</h2>
        <p>Product Details</p>
    </div>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/2c4cad12-1c2a-4a6c-9edc-68beb68841c3.png align="center")

**Browser Preview:**

After Inspect to show how it is block level element

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/2c366974-64f4-4066-b3d7-c3439327e542.png align="center")

9. `<span>` Groups a small portion of a text in line

**Code:**

```html
<p>Price:<span>500</span></p>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/4e074768-230a-4abc-8c1b-eb372851ceac.png align="center")

**Browser Preview:**

After Inspect to show span is inline element

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/82c89687-a839-42e1-9fa7-7bbc1cc474c9.png align="center")

10. `<a>` Ceates a hyperlink to another page or website

**Code:**

```html
<a href="https://google.com">Visit Google</a>
```

If you want to open in new tab then write `target="_blank"`

```html
<a href="https://google.com" target="_blank">Visit Google</a>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/97f148a9-8bcf-424f-86d4-e9db1eab022f.png align="center")

11. `<img>` Embeds an image in a web page

Code:

```html
<img src="brian-zajac-4LngtXlsjJs-unsplash.jpg" alt="My Photo" height="200px" width="200px">
```

`src` is a attribute of an element and define the path of an image.

`alt` is alternative text which is show when the image is not loaded.

`height` and `width` is a dimension of the image.

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/4a31e89f-122e-4eb6-ac4a-5fd079a29b3e.png align="center")

12. `<br>` insert a line break

**Code:**

```html
 Hello<br>World
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/48bc8db1-2b84-4da5-b00e-1655a7a0d79f.png align="center")

13. `<hr>` Represents a thematic break between sections

**Code:**

```html
<p>Section one</p>
 <hr>
<p>Section Two</p>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/000a4ac5-baaf-4707-bdc9-b4efa064344b.png align="center")

14. `<strong>` Marks text as a strongly important,usually displayed in bold

**Code:**

```html
 <strong>!Important Notice</strong>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/8eea8421-91bf-44d2-bccc-c8cdd2094b0c.png align="center")

15. `<em>` Adds stress emphasis to text, usually displayed in italics

**Code:**

```html
<p>I <em>really</em> Like Coding</p>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/01b87d66-670b-45d5-bed4-1ba3490c5d17.png align="center")

16. `<i>` Represents text in a alternate voice or style,usually displayed in italics

**Code:**

```html
<p>The Term <i>HTML</i> is Widely used</p>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/535cf73d-b8e9-4ff4-bdc1-a599dc897a62.png align="center")

17. `<b>` Draw attention to text without indicating extra importance.

**Code:**

```html
 <p>Today's offer:<b>50% off</b></p>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/dde66e43-1336-4f51-8e6c-80d1f92ac6d3.png align="center")

18. `<button>` Creates a Clickable button

Code:

```html
 <button>Click me</button>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/928994f8-b377-437c-9555-7973ed4a8699.png align="center")

19. `<input>` Creates an input control for entering data
20. `<label>` Provide a label for form control

**Code:**

```html
<label for="email">Email</label>
<input type="email"/>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/84c778d0-5925-4017-918c-5179a9a5b17a.png align="center")

21. `<form>` Group controls used to Collect and submit user information

**Code:**

```html
<form>
 <label for="email">Email</label>
 <input type="email" placeholder="Enter your Email"/>
 <button>Submit</button>
 </form>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/9f39ff7a-0a68-4d12-be4a-880d4c4a0fba.png align="center")

22. `<textarea>` creates a multiline text input. You can increase the height and width of textarea by setting `rows` and `cols` attributes.

**Code:**

```html
<textarea placeholder="Write Your message"></textarea>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/3c3d1505-b25f-47c9-b7a3-2eb5ff249149.png align="center")

With `rows` and `cols` attributes

**Code:**

```html
<textarea placeholder="Write Your message" rows="20" cols="40"></textarea>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/fb93ae18-3517-40a7-b275-cd51b12c227e.png align="center")

23. `<select>` Creates a Dropdown menu

**Code:**

```html
 <select>
    <option>India</option>
    <option>Japan</option>
 </select>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/ca6cadcd-7431-4fb0-921c-334ab446b548.png align="center")

if you want to disable by defaul dropdown values write this code:

**Code:**

```html
<select>
    <option value="" selected disabled hidden>Select a Country</option>
    <option>India</option>
    <option>Japan</option>
 </select>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/304fb69d-f3ef-42ab-80f0-e7144b93664b.png align="center")

24. &lt;ul> Creates a unordered list usually with bullets.

**Code:**

```html
<ul>
    <li>HTML</li>
    <li>CSS</li>
 </ul>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/c1891ad1-eedc-45d5-9462-12cbcb0acf71.png align="center")

25. `<ol>` Creates an ordered list, usually numbered

**Code:**

```html
<ol>
    <li>Learn HTML</li>
    <li>Learn CSS</li>
 </ol>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/9ab50490-269c-4920-8a20-b274b97d2769.png align="center")

26. `<li>` Defines an item inside a list.

**Code:**

```html
 <ul>
    <li>Javascript</li>
 </ul>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/ff8ccf9c-ab23-4f9c-81b6-ab1bf74b6d80.png align="center")

27. `<table>` Create a table for structure data. You can apply border using CSS.

**Code:**

```html
 <table>
    <tr>
        <td>Aman</td>
        <td>Developer</td>
    </tr>
 </table>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/1fa04007-faf8-432d-b683-58a3001db879.png align="center")

28. `<tr>` Defines a roe in table

**Code:**

```html
<table>
    <tr>
        <td>Aman</td>
        <td>Developer</td>
    </tr>
     <tr>
        <td>Aman</td>
        <td>25</td>
    </tr>
 </table>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/fde3f36f-8c43-4d31-88e0-dd682f8748a7.png align="center")

29. `<th>` Defines a header cell in a table.
30. `<td>` Defines a regular data cell in table

**Code:**

```html
<table>
    <tr>
        <th>Name</th>
        <th>Age</th>
    </tr>
    <tr>
        <td>Aman</td>
        <td>23</td>
    </tr>
     <tr>
        <td>Kunal</td>
        <td>25</td>
    </tr>
 </table>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/1368686c-19ad-4399-be2a-c1d3c55c0d64.png align="center")

31. `<header>` Represents a introductory content for a page or section.

**Code:**

```html
 <header>
    <h1>My Website</h1>
 </header>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/c576b7b3-931e-4381-b9fd-b0000f829250.png align="center")

32. `<nav>` groups important navigation links

**Code:**

```html
 <nav>
    <a href="/">Home</a>
    <a href="/about">About</a>
 </nav>
```

33. `<main>` contains the main content of webpage

**Code:**

```html
 <main>
    <h1>Dashboard</h1>
 </main>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/b7d8cb82-1be9-43ca-b3fb-c267b41a05eb.png align="center")

34. `<section>` Groups related content into a section

**Code:**

```html
 <section>
    <h2>Our Services</h2>
    <p>Web Development Service</p>
 </section>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/ba396230-5eb0-420f-ad53-22c67c42387f.png align="center")

35. `<article>` Represents self contained content , such as blog post.

**Code:**

```html
 <article>
    <h2>My First blog Post</h2>
    <p>This is my blog post</p>
 </article>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/c6b188b1-01ca-427c-9051-631af81da0e1.png align="center")

36. `<footer>` Represent a footer content of a page or section

**Code:**

```html
 <footer>
    <p>Copyright 2026</p>
 </footer>
```

**Browser Preview:**

![](https://cdn.hashnode.com/uploads/covers/6a670b7b711c6f3b57c87574/78210719-19da-404f-9e7e-88f304135884.png align="center")

37. `<link>` link external resources, commonly a CSS stylesheet

**Code:**

```html
  <link rel="stylesheet" href="style.css">
```

38. `<iframe>` Embeds another webpage or supported external content.

**Code:**

```html
<iframe src="https://example.com" title="Example website"></iframe>
```

39. `<video>` embeds video content.

**Code:**

```html
<video controls>
    <source src="video.mp4" type="video/mp4">
</video>
```

40. `<audio>` Embeds Audio content

**Code:**

```html
<audio controls src="audio.mp3"></audio>
```

41. `<figure>` Groups self-contained content such as an image or diagram.

**Code:**

```html
<figure>
    <img src="laptop.jpg" alt="Laptop">
    <figcaption>A laptop</figcaption>
</figure>
```

42. `<detail>` Creates a disclosure widget that users can expand or collapse.

**Code:**

```html
<details>
    <summary>Read more</summary>
    <p>Additional information.</p>
</details>
```
