HTML Basic Syntax & Document Structure
HTML Basic Syntax & Document Structure
Understanding HTML syntax is the foundation of every website you will ever build. HTML (HyperText Markup Language) is not a programming language — it is a markup language that uses tags to structure content on the web. Before you can build responsive, semantic, SEO-friendly websites, you need to master how an HTML document is written and organized.
What Is HTML Syntax?
HTML syntax refers to the set of rules that define how HTML tags, elements, and attributes must be written so that browsers can correctly interpret and render your webpage. Every valid HTML document follows a predictable pattern of nested tags, opening and closing elements, and attribute-value pairs.
Anatomy of an HTML Tag
An HTML tag typically consists of three parts:
- Opening tag — e.g.
<p> - Content — the text or nested elements inside the tag
- Closing tag — e.g.
</p>
Example:
<p>This is a paragraph.</p>The Structure of a Complete HTML Document
Every modern HTML5 document follows this basic structure:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document Title</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>Let's break this down:
<!DOCTYPE html>tells the browser this is an HTML5 document.<html>is the root element that wraps all content.<head>contains metadata, the page title, and links to CSS/JS — it is not visible on the page.<body>contains everything the user actually sees in the browser.
Nesting Rules & Indentation
HTML elements can be nested inside one another, but they must be closed in the correct order — this is called proper nesting. Improperly nested tags can break your layout and cause validation errors.
<!-- Correct nesting -->
<div>
<p><strong>Bold text</strong></p>
</div>
<!-- Incorrect nesting -->
<div>
<p><strong>Bold text</p></strong>
</div>Case Sensitivity & Best Practices
HTML tags are not case-sensitive, but modern coding conventions (and the HTML5 spec) recommend using lowercase tags and attributes for consistency, readability, and compatibility with XHTML-style tooling.
Void (Self-Closing) Elements
Some elements do not require a closing tag because they cannot contain content. These are called void elements, and they are a common trending topic in modern HTML5 best practices:
<br>— line break<img>— image<input>— form input<hr>— horizontal rule<meta>— metadata
Why Document Structure Matters for SEO & Accessibility
A well-structured HTML document isn't just about passing validation — it directly impacts SEO ranking, accessibility (a11y), and how fast browsers can parse and render your page. Search engines and screen readers rely on a logical document structure to understand your content.
Key Takeaways
- HTML syntax follows a strict tag-based structure of opening/closing tags and attributes.
- Every HTML5 document needs
<!DOCTYPE html>,<html>,<head>, and<body>. - Proper nesting and lowercase syntax are modern best practices.
- Void elements like
<img>and<br>don't need closing tags.
Press Run to execute.
Press Run to execute.
Write a complete HTML5 document with a DOCTYPE, html, head, and body tag. Inside the body, add an h1 heading with your name and a paragraph describing yourself.
Press Run to execute.
This is a self-check — compare your result with the expected output above.
Was this page helpful?