What are HTML Elements?
HTML elements are the foundation of any web page. An HTML element consists of a start tag, content, and an end tag. Elements can represent things like paragraphs, headings, links, images, and more.
For example, the following is a paragraph element:
<p>This is a paragraph.</p>
Basic HTML Elements
Here are some of the most commonly used HTML elements:
- <h1> to <h6>: Heading elements, with
<h1>
being the most important and<h6>
the least important. Example:
<h1>This is a main heading</h1>
<p>This is a paragraph of text.</p>
<a href="https://www.example.com">Click here</a>
<img src="image.jpg" alt="Description of the image">
<ul> <li>First item</li> <li>Second item</li> </ul>
Block vs Inline Elements
HTML elements can be broadly classified into two categories:
- Block Elements: These elements take up the full width of the container and always start on a new line. Examples include:
- <div>
- <h1> to <h6>
- <p>
- <ul>, <ol>
- Inline Elements: These elements take up only as much width as needed and do not start on a new line. Examples include:
- <a>
- <span>
- <img>
- <strong>, <em>
Block elements can contain other block or inline elements, while inline elements usually contain only other inline elements.
Nested Elements
HTML elements can be nested inside each other to create more complex structures. For example:
<div> <h2>This is a heading inside a div</h2> <p>This is a paragraph inside a div.</p> </div>
In this example, the <h2>
and <p>
elements are nested inside the <div>
element. This allows for organizing the structure of the webpage.