Basics

HTML Elements

Using HTML Elements

HTML elements are building blocks like <div> and <span>, nesting to form pages.

What is an HTML Element?

At its core, an HTML element is a piece of a web page, defined by a start tag and often closed with an end tag. It may also contain content and other nested elements. HTML elements form the structure of web documents and are essential for creating web pages.

Basic Structure of an HTML Element

An HTML element generally consists of:

  • Start Tag: Indicates the beginning of an element. For example, <div>.
  • Content: The information or nested elements between the opening and closing tags.
  • End Tag: Marks the end of an element. For example, </div>.

Void Elements

Void elements, also known as self-closing tags, do not have an end tag. These elements are empty and cannot contain any content. Common examples include <br>, <img>, and <meta>.

Nesting HTML Elements

HTML elements can be nested within each other to build complex structures. Nesting allows for the creation of hierarchies and the grouping of elements. It is important to ensure that elements are properly nested, with opening and closing tags correctly paired, to maintain valid HTML.

Common HTML Elements

There are numerous HTML elements, each serving a specific purpose. Some of the most common include:

  • <div>: A generic container for other elements.
  • <span>: An inline container for text and other inline elements.
  • <p>: Represents a paragraph.
  • <a>: Defines a hyperlink.
  • <h1> to <h6>: Represent headings, with <h1> being the highest level and <h6> the lowest.
Previous
Doctype