Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH RUST

Web Development - HTML Elements


HTML Elements

HTML pages are built using elements. An HTML element tells the browser how to display content - for example, a heading, a paragraph, or an image.

Each element usually has an opening tag and a closing tag, with content in between:

Example

<p>This is a paragraph.</p>
Try it Yourself »

Example explained:

Part Description
<p> Start tag - tells the browser where the paragraph begins
This is a paragraph. Content - the text inside the element
</p> End tag - tells the browser where the paragraph ends

Tip: Most HTML elements come in pairs like <p> and </p>.


Nested Elements

HTML elements can be nested - meaning you can put elements inside other elements.

The browser reads them from top to bottom and inside to outside:

Example

<h1>My First Page</h1>
<p>This is a <b>bold</b> paragraph.</p>
Try it Yourself »

Here, the <b> element is inside the <p> element.

Tip: Always close elements in the opposite order they were opened. Think of it like stacking boxes - the last one opened should be the first one closed.


Empty Elements

Some elements do not have closing tags, like <br>. These are called empty elements.

The <br> tag inserts a line break:

Example

<p>This is the first line.<br>This is the second line.</p>
Try it Yourself »

Other common empty elements:

  • <hr> - horizontal line
  • <img> - image
  • <meta> - metadata inside the head

Case Sensitivity

HTML tags are not case-sensitive. This means <P> and <p> mean the same thing - but the convention (and best practice) is to use lowercase tags:

Example

These two lines are equivalent:

<P>This is a paragraph.</P>
<p>This is a paragraph.</p>
Try it Yourself »

Whitespace in HTML

HTML ignores extra spaces and line breaks in your code. Whether you write your text on one line or several, it will appear the same in the browser.

Example

These two paragraphs display the same:

<p>This   paragraph   has   many   spaces.</p>

<p>This paragraph has many spaces.</p>
Try it Yourself »

Tip: If you want to preserve spacing, use the <pre> element, which keeps your text formatting exactly as written.


Summary

  • An HTML element is everything from the start tag to the end tag.
  • Most elements have both opening and closing tags.
  • Some elements are empty (no closing tag).
  • HTML ignores extra spaces and new lines.

Next, you'll learn about the most common HTML elements for structuring a page - headings and paragraphs.

Next » HTML Headings


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.