Basics
HTML Elements
Using HTML Elements
HTML elements are building blocks like <div> and <span>, nesting to form pages.
What Are HTML Elements?
HTML elements are the foundational components of HTML documents. They define the structure and content of a web page. An HTML element typically consists of a start tag, content, and an end tag. For example, the <p> element for paragraphs is written as:
Common HTML Elements
Some of the most commonly used HTML elements include:
- <div>: A block-level element used for grouping other elements.
- <span>: An inline element used for styling a part of the text.
- <a>: An anchor element for creating hyperlinks.
- <img>: An image element for embedding images.
- <ul> and <ol>: Used for creating unordered and ordered lists, respectively.
Nesting HTML Elements
HTML elements can be nested within each other to create complex structures. Nesting involves placing one or more HTML elements inside another element. This is commonly used in webpage layouts. For example, you can nest a <span> inside a <div>:
Self-Closing HTML Elements
Some HTML elements do not have content and are self-closing. These elements include:
- <br>: Inserts a line break.
- <hr>: Creates a horizontal rule.
- <img>: Embeds an image, as previously mentioned.
In HTML5, self-closing tags do not require a trailing slash, but including it is not incorrect.
Understanding Element Attributes
HTML elements can have attributes that provide additional information about the element. Attributes are always specified in the start tag and usually come in name/value pairs like name="value"
.
For example, the <a> element uses the href
attribute to define the link destination:
In the next post, we will explore HTML attributes in greater detail, examining how they modify the behavior and presentation of elements.
Basics
- Previous
- Doctype
- Next
- Attributes