Select Page

Empty Tags

How to correct empty XHTML/HTML tags.
Empty tags, also known as self-closing tags or void elements, are HTML elements that do not require a closing tag. These elements represent content or elements that do not have any inner content or do not require a closing tag for their intended functionality. Many HTML elements require an opening tag and a corresponding closing tag to enclose the intended content. For example, a paragraph element is written as <p>…</p>, where the content goes between the opening <p> tag and the closing </p> tag. Certain HTML elements are designed to be self-closing and are represented by empty tags, where the closing tag is omitted. Here are four examples of commonly used HTML empty tags:
  1. <br> – A line break within a text block.
  2. <img> – An image element to embed images in a web page.
  3. <input> – An input control element, such as text fields, checkboxes or radio buttons for user input.
  4. <meta> – The metadata about an HTML document, such as character encoding, viewport settings, and search engine optimization information.
These are just a few examples of HTML empty tags. They are defined as self-closing in the HTML specification, and it is important to use them correctly according to their intended purpose. XHTML, the stricter and XML-based version of HTML, requires empty tags to have a closing slash before the closing angle bracket, such as <br />, to comply with XML syntax rules. Standard HTML does not require the slash and considers it optional. Using empty tags correctly helps maintain valid and well-formed HTML code. Ensure that appropriate elements are used as self-closing tags and that regular elements with content are enclosed with both an opening and a closing tag.