HTML Tags and Elements

HTML Living Standard

Read a single HTML element first, then see how elements fit inside one another.

On this page

HTML Tags

A tag is a marker in the HTML code. It uses angle brackets. In <p>, p is the name of the tag and starts a paragraph. In </p>, the slash marks the end. A closing tag uses the same name with a slash.

<p>Your page is ready.</p>

What to expect The page shows “Your page is ready.” as a paragraph.

HTML Elements

An element is a piece of the page with a purpose. Here the paragraph element consists of the opening tag <p>, the text “Registration is open.”, and the closing tag </p>. The <hr> element marks a break between topics. It is a void element, so it has neither content nor a closing tag.

<!-- Paragraph element: opening tag, text, and closing tag -->
<p>Registration is open.</p>

<!-- Void element: a break between topics -->
<hr>
<p>Classes start on Monday.</p>

What to expect The browser usually displays a horizontal line between the paragraphs.

HTML Attributes

An attribute gives the browser extra information about an element. Write it after the tag name in the start tag. Here lang is the attribute name and "en" is its value. It identifies the paragraph language as English.

<p lang="en">Your page is ready.</p>

What to expect The text still reads “Your page is ready.”. The language information belongs to the element.

Case Insensitivity in HTML

HTML tag names and attribute names are case-insensitive. <P> and <p> create the same paragraph element. Use lowercase for tag and attribute names. Class values are case-sensitive in standards mode, so .note matches "note".

How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>HTML Case Insensitivity</title>
  <style>
    .note { color: teal; }
  </style>
</head>
<body>
  <P CLASS="note">First paragraph</P>
  <p class="note">Second paragraph</p>
  <p class="Note">Third paragraph</p>
</body>
</html>

What to expect All three lines appear as paragraphs. The first two are teal. The third uses the default text color. Change "Note" to "note" to give the third paragraph the same color.

Nesting HTML Elements

Nesting means putting one element inside another. Here <main> is the parent and its <h1> and <p> are its direct children. The closing tags for both children come before </main>.

<main>
  <h1>Learning Center</h1>
  <p>Registration is open.</p>
</main>

What to expect The heading and paragraph both belong to the same main content area.

Official references