#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
HTML Fundamentals

HTML Elements

An HTML element is a building block of a web page, usually made of an opening tag, some content and a closing tag, such as <p>Hello</p>. Elements tell the browser what each piece of content is: a heading, a paragraph, a link, a list, an image. The browser turns them into a tree called the DOM, which CSS styles and JavaScript can change.

Anatomy of an element

<a href="/pricing" class="nav-link">Pricing</a>
<!--
  <a ...>        opening tag (element name "a")
  href, class   attributes
  Pricing       content
  </a>          closing tag
-->

The tag is the markup in angle brackets; the element is the whole thing, tags plus content. Element names are not case-sensitive, but lowercase is standard.

Void elements have no content

Some elements cannot contain anything, so they have no closing tag. These are called void elements. The common ones are <img>, <br>, <hr>, <input>, <meta>, <link> and <source>. You may see them written with a trailing slash, like <br />; in HTML that slash is allowed but ignored. In JSX it is required.

Nesting builds the page structure

Elements can contain other elements. A list holds list items, a list item can hold a link, and a link can hold text. Nested elements must close in the reverse order they opened, like stacking and unstacking boxes.

<!-- Correct -->
<p>Read the <strong><em>whole</em></strong> guide.</p>

<!-- Wrong: tags overlap -->
<p>Read the <strong><em>whole</strong></em> guide.</p>

<ul>
  <li><a href="/html">HTML</a></li>
  <li><a href="/css">CSS</a></li>
</ul>

Browsers try to repair overlapping tags, but each browser may guess differently, which leads to odd styling and scripts that cannot find the element they expect.

Block-level and inline behaviour

By default, some elements start on a new line and stretch across the available width, while others sit inside a line of text.

Usually blockUsually inline
div, p, h1 to h6, ul, ol, li, section, form, tablespan, a, strong, em, code, img, label, button

This is only the default display; CSS can change it. What matters more is the content model, the rules about what may go inside what. A <p>, for instance, cannot contain block elements like <div> or another <p>.

A trap with paragraphs and lists

If you place a <div> or a <ul> inside a <p>, the browser closes the paragraph automatically just before it. Your markup looks fine in the editor, but in the DOM the list ends up outside the paragraph, and CSS selectors like p ul match nothing. In React this shows up as a hydration warning. When a block needs other blocks inside, use a <div> or a semantic container instead of <p>.

A similar trap: putting anything other than <li> directly inside <ul> or <ol>. Wrap extra content inside a list item.

Choosing the right element

Pick elements for what the content is, not how it looks. Use <button> for actions and <a> for navigation, headings for headings, and lists for groups of items. The right element gives you keyboard support, screen reader meaning and search engine understanding for free, and you can always restyle it with CSS. The next lesson on semantic HTML5 elements builds on this idea.

Remember

  • An element is opening tag, content and closing tag.
  • Void elements like img and input have no closing tag.
  • Close nested tags in reverse order.
  • Respect the content model; paragraphs cannot hold blocks.

Ready to master real-world web development?

Learn HTML, CSS3, Bootstrap and JavaScript hands-on with mentor-led sessions.

Explore Course