Skip to main content

Command Palette

Search for a command to run...

#11 Understanding HTML Tags and Elements

Updated
3 min read
P
Since I am developer. My blogs are related to Tech and also blogs write during web dev cohort by chai code.

Think of HTML (HyperText Markup Language) as the skeleton of a webpage. Just as a skeleton provides the structure for a body, HTML provides the structure for a website. It tells the browser, "This is a heading," "This is a paragraph," or "This is an image."

Without HTML, the web would just be a wall of unorganized text.

1. What is an HTML Tag?

A Tag is a special keyword surrounded by angle brackets (< and >). Tags act like "instructions" for the browser. Most tags come in pairs:

  1. Opening Tag: <p> (Tells the browser: "Start a paragraph here")

  2. Closing Tag: </p> (Tells the browser: "End the paragraph here")

2. Tag vs. Element: The Key Difference

People often use these words interchangeably, but they are slightly different.

  • The Tag: Just the markers (<p> or </p>).

  • The Content: The actual text or image inside.

  • The Element: The whole package (Opening Tag + Content + Closing Tag).

3. Self-Closing (Void) Elements

Some things on a webpage don't have "content" inside them—they just are. For example, an image or a line break. These are called Self-closing or Void elements because they don't need a separate closing tag.

  • <img>: For images.

  • <br>: For a single line break.

  • <hr>: For a horizontal line.

4. Block-level vs. Inline Elements

This is the most important concept for layout. Every HTML element has a default "display" behavior.

Block-level Elements

These always start on a new line and take up the full width available. Think of them as large boxes that stack on top of each other.

  • Examples: <div>, <h1> to <h6>, <p>, <ul>.

Inline Elements

These do not start on a new line. They only take up as much width as necessary. Think of them as labels on a shelf that sit side-by-side.

  • Examples: <span>, <a> (links), <strong> (bold text).

5. Commonly Used Tags

As you build your Next.js and React components, you'll use these constantly:

TagPurposeType
<div>A generic container for other elementsBlock
<h1>The main heading of a pageBlock
<p>A paragraph of textBlock
<a>A hyperlink to another pageInline
<img>Displays an imageInline
<span>A generic container for textInline

6. Try it yourself

If you are on your laptop in Indore right now, you can see HTML in action. Right-click anywhere on this page and select "Inspect". You will see the "Elements" tab, which shows you the exact HTML skeleton of this website.