HTML elements are the building blocks of HTML pages. An element is defined by a start tag, some content, and an end tag. Elements can also have attributes that provide additional information about the element.
HTML elements are not the same as HTML tags. HTML tags are used to create HTML elements. For example, the <p> tag creates a paragraph element.
Inline elements do not start on a new line and only take up as much width as necessary. They can be nested inside block-level elements.
<span>
A generic inline container
<a>
Creates a hyperlink
<strong>, <em>
Emphasis elements for importance and stress
<img>
Embeds an image
Copy
<p> This is a paragraph with <span style="color: blue;">blue text</span> and a <a href="https://example.com">link to example.com</a>. <strong>This text is important</strong> and <em>this is emphasized</em>.</p><p>Here's an image: <img src="image.jpg" alt="Description" /></p>
<h1>Main Heading</h1><h2>Subheading</h2><p>This is a paragraph of text.</p><blockquote>This is a blockquote.</blockquote><pre>This is preformatted text.</pre><code>This is code.</code>
<!-- Image --><img src="image.jpg" alt="Description of the image" width="300" height="200" /><!-- Audio --><audio controls> <source src="audio.mp3" type="audio/mpeg" /> Your browser does not support the audio element.</audio><!-- Video --><video width="320" height="240" controls> <source src="video.mp4" type="video/mp4" /> Your browser does not support the video element.</video>
HTML elements can be nested inside other elements, creating a hierarchical structure.
Copy
<div class="container"> <h1>My Website</h1> <p>Welcome to my website. Here's some <strong>important</strong> information.</p> <div class="content"> <h2>About Me</h2> <p>I am a <em>web developer</em> who loves <a href="#">HTML</a>.</p> </div></div>
Use semantic elements whenever possible to improve accessibility and SEO
Close all elements properly to maintain valid HTML
Nest elements correctly to create a proper document structure
Use lowercase for element names for better readability and consistency
Include alternative content for media elements to improve accessibility
Modern HTML5 introduces many semantic elements like <header>, <footer>, <article>, <section>, and more. These elements provide meaning to your HTML structure and should be used instead of generic <div> elements when appropriate.
Most HTML elements are supported by all modern browsers. However, some newer HTML5 elements might not be fully supported in older browsers. Always check browser compatibility when using newer elements.
Internet Explorer has limited support for some HTML5 elements. If you need to support older browsers, consider using polyfills or fallback solutions.