Skip to main content

Empty HTML Elements – What Is an Empty HTML Element?

An empty HTML element consists of only an opening tag.

In other words, empty HTML elements have no content or closing tag.

note

Empty elements are sometimes called self-closing elements.

Here's an illustration:

Anatomy of an empty HTML element

An empty HTML element has only an opening tag
info

Elements with content and closing tags are called Regular HTML Elements.

Below are some of the widely used empty HTML elements.

What Is an <img> Element?

An <img> element embeds an image to a webpage.

Here's an example:

<img
src="https://www.your-image-url.com/the-image.jpg"
width="120"
height="90"
alt="Example of an image element"
/>

Note the following:

  • src attribute specifies the image's URL.
  • The width and height attributes specify the image's dimensions.
  • An alt (alternative text) attribute is essential for accessibility. Browsers display it whenever the image fails to load. And screen readers read it to their users.
  • Suppose your image is purely decorative. In that case, provide an empty alt attribute (alt="").

:::

What Is an <input> Element?

The <input> element creates an input field for entering data.

Here's an example:

<input type="text" name="name-of-list" />
note
  • The type attribute states the type of input element the browser should display.
  • The name attribute specifies the input element's name.

Overview

This article discussed what an empty HTML element is. We also saw examples of some of the widely used ones.