Chapter 1 of ?
html 8 min read

HTML Mastery — Chapter 2: HTML Basic Syntax & Elements

Section 1 · Chapter 2

HTML Basic Syntax & Elements

An HTML element is defined by a start tag, some content, and an end tag. In this chapter, you will master the syntax of HTML elements, empty elements, headings, paragraphs, comments, and line breaks.

Live Code Example

Click Try it Yourself » to edit and test HTML elements live in the playground.

Example: Nested HTML Elements

<!DOCTYPE html> <html lang="en"> <body> <h1>Main Article Heading</h1> <p>This paragraph contains <strong>bold text</strong> and a line break.<br>Here is line two.</p> <!-- This is an HTML comment --> </body> </html>
Try it Yourself »

2.1 Anatomy of an HTML Element

An HTML Element is everything from the start tag to the end tag:

Start Tag Element Content End Tag
<h1> My First Heading </h1>
<p> My first paragraph text. </p>
<br> None (Empty Element) None
Never Forget the End Tag: Some HTML elements will display correctly if you forget the end tag, but never rely on it! Unclosed tags can cause unexpected layout bugs.

HTML Element Structure Diagram

<p class="text"> Start Tag + Attribute Hello World Element Content </p> End Tag

2.2 HTML Headings (<h1> to <h6>)

Headings are defined with the <h1> to <h6> tags. Headings are important for accessibility and Search Engine Optimization (SEO).

  • <h1> should be used for main titles (only one <h1> per page).
  • <h2> to <h6> represent sub-sections in hierarchical order. Never skip heading levels (e.g. going from <h1> straight to <h4>).

Example: Heading Hierarchy

<h1>Main Book Title</h1> <h2>Chapter 1: Getting Started</h2> <h3>1.1 Installation Guide</h3> <h4>Step A: Download Files</h4>
Try it Yourself »

2.3 Paragraphs, Line Breaks (<br>) & Horizontal Rules (<hr>)

The <p> element defines a block of text paragraph.

HTML offers two special empty elements for layout formatting inside text:

  • <br> — Inserts a single line break without starting a new paragraph block.
  • <hr> — Inserts a horizontal rule (thematic break) to separate content sections visually.

Example: Paragraphs with <br> and <hr>

<h2>Section One</h2> <p>This is paragraph one text.<br>This sentence starts on a new line!</p> <hr> <h2>Section Two</h2> <p>Paragraph two appears after the horizontal rule.</p>
Try it Yourself »

2.4 HTML Comments

HTML comments are written as <!-- comment text -->. Comments are ignored by the browser and will not be displayed on the web page.

Comments are essential for documenting your code, making complex layouts understandable, or temporarily hiding elements during debugging.

Example: HTML Comments

<!-- Main Navigation Header --> <h1>Welcome to My Website</h1> <!-- TODO: Add user profile photo here --> <p>Profile description paragraph.</p>
Try it Yourself »

💻 Chapter 2 Hands-On Code Challenge

Build a structured blog post layout applying element syntax, proper heading hierarchy, line breaks, horizontal dividers, and comments:

  1. Add an <!-- Article Header --> comment before the main title.
  2. Add an <h1> for the blog post title and an <h2> for Section 1.
  3. Write a paragraph with a <br> line break separating two sentences.
  4. Add an <hr> horizontal rule divider.
  5. Add an <h2> for Section 2 and a second paragraph.

Starter Challenge Code

<!DOCTYPE html> <html lang="en"> <body> <!-- TODO: Add comments, headings, paragraphs, br, and hr --> </body> </html>

Chapter 2 Key Takeaways

  • An HTML element consists of a start tag, content, and an end tag (e.g. <p>text</p>).
  • Empty elements like <br> and <hr> have no closing tag.
  • Headings range from <h1> (most important) to <h6> (least important); use them hierarchically.
  • HTML comments are written as <!-- comment --> and are not rendered on the web page.
Done with this chapter?
Mark it complete to track your progress and unlock your certificate.
Next Up

Learner Reviews

Write a Review
Share your experience to help other learners.
Your Rating *