HTML Syntax and Structure
Understanding HTML Syntax and Structure
Think of HTML as the skeleton of every web page. It doesn’t style or animate — it structures. To master HTML, you first need to understand how it’s written and how its pieces fit together.
HTML Document Structure
Every HTML file begins and ends in a specific way. This structure helps browsers interpret and display your content correctly.
<!DOCTYPE html>
<html>
<head>
<title>My Web Page</title>
</head>
<body>
<h1>Hello World</h1>
<p>This is a paragraph.</p>
</body>
</html>

This structure acts like a blueprint. Let’s break it down:
- <!DOCTYPE html>: Declares that this is an HTML5 document
- <html>: The root element wrapping everything
- <head>: Metadata, title, and links (not displayed)
- <body>: The visible content — what users actually see
What is <!DOCTYPE html>?
This declaration goes at the very top of every HTML file. It's not a tag — it’s a declaration. It tells the browser: “This page uses HTML5.”
Why is that important? Because browsers behave differently depending on the declared document type. Without this line, your layout may break unexpectedly.
HTML Tags and Elements
Tags are the language of HTML. Most tags come in pairs — an opening tag and a closing tag — and they wrap content.
<p>Apple</p>
<h2>Banana</h2>
<strong>Cherry</strong>

Here’s the anatomy of a tag:
<p>
— Opening tagApple
— Content</p>
— Closing tag
Together, this is called an HTML element.
Nesting HTML Elements
Nesting means placing elements inside other elements. It must be done carefully — the opening and closing order matters.
<p>I love <strong>cherry</strong> pie.</p>

Here, the <strong>
tag is nested inside a paragraph. The output shows “cherry” in bold. Always close the inner tag before the outer tag. This is valid:
<em>Text with <strong>emphasis</strong></em>
This is invalid and might break layout:
<em>Text with <strong>emphasis</em></strong>
HTML Comments
Comments are notes for developers. They don’t show on the page and are ignored by the browser. Use them to explain, organize, or temporarily disable code.
<!-- This is a comment -->
<p>Hello World</p>
<!-- <p>This line won't show</p> -->

Notice how the second paragraph is "commented out" — it's in the code, but not in the output. Great for debugging or reminders.
Common Syntax Mistakes to Avoid
Here are some common slip-ups beginners make — and how to dodge them:
- Unclosed tags: Always write both opening and closing tags unless it's a self-closing tag (like
<br>
or<img>
). - Improper nesting: Tags should be closed in the reverse order they were opened.
- Using uppercase: HTML is case-insensitive, but lowercase is the standard.
Putting It All Together
Let’s build a full example that uses proper structure, nesting, and comments.
<!DOCTYPE html>
<html>
<head>
<title>Fruit Page</title>
</head>
<body>
<!-- Main heading -->
<h1>Welcome to My Fruit Basket</h1>
<p>These are my favorite fruits:</p>
<ul>
<li>Apple</li>
<li>Banana</li>
<li><strong>Cherry</strong></li>
</ul>
</body>
</html>

Summary
HTML syntax is what makes a webpage readable — not just by people, but by browsers. You’ve now seen:
- How an HTML document is structured
- The role of the
<!DOCTYPE>
declaration - What tags and elements are, and how to nest them
- How to use comments for clarity
Mastering syntax isn’t glamorous — but it’s the foundation. And once that’s strong, everything else becomes easier to build.
Next Up
In the next tutorial, we’ll dive deeper into HTML Text Formatting, where you’ll learn how to bold, italicize, highlight, and structure content with finesse.