What are Self Closing Tags in HTML? Last Updated : 14 Oct, 2024 Comments Improve Suggest changes Like Article Like Report Self-closing tags, also known as void elements, are HTML elements that do not require a separate closing tag. These tags are self-contained and are typically used for elements that do not have any content between an opening and closing tag. Self-closing tags help keep the HTML structure clean and concise.These are the following topics that we are going to discuss:Table of ContentSelf-Closing TagsCommon Self-Closing TagsHow to Use Self-Closing Tags?Importance of Self-Closing TagsDifferences in HTML VersionsConclusionSelf-Closing TagsIn HTML, a self-closing tag is an element that does not need an explicit closing tag. It is written in a single line, and the tag is "closed" by including a forward slash (/) before the closing angle bracket (>). While HTML5 does not strictly require the use of the forward slash in self-closing tags, it is still considered a good practice for compatibility with XML.Common Self-Closing TagsSome of the most common self-closing tags in HTML include:<img>: Used to embed images.<br>: Inserts a line break.<hr>: Creates a horizontal rule (line).<input>: Defines an input control.<meta> tag: Provides metadata about the HTML document.<link> tag: Used to link external resources like stylesheets.How to Use Self-Closing Tags?To use self-closing tags in HTML, simply write the tag followed by a forward slash before the closing angle bracket. Syntax:<img src="image.jpg" alt="Description of image" />Example: This example demonstrates the use of various self-closing tags within an HTML document. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Self-Closing Tags Example</title> </head> <body> <h1>Self-Closing Tags in HTML</h1> <h2>Image Example</h2> <img src="https://media.geeksforgeeks.org/gfg-gg-logo.svg" alt="Placeholder Image" /> <h2>Line Break Example</h2> <p>This is a paragraph.<br>This line breaks.</p> <h2>Horizontal Rule Example</h2> <hr /> <h2>Input Example</h2> <form> <label for="name">Name:</label> <input type="text" id="name" name="name" /> <input type="submit" value="Submit" /> </form> </body> </html> Output:OutputImportance of Self-Closing TagsSelf-closing tags are important for several reasons:Simplification: They reduce the amount of code written, making it cleaner and easier to maintain.Performance: Less code can lead to faster parsing by browsers, improving overall performance.Consistency: Using self-closing tags helps maintain a consistent and predictable structure in HTML documents.Differences in HTML VersionsIt's important to note that the rules regarding self-closing tags have evolved across different versions of HTML:HTML5: In HTML5, self-closing tags do not require a forward slash. For example, <img src="image.jpg" alt="Description of image"> is valid.XHTML: In XHTML, self-closing tags must include the forward slash, as it adheres to XML standards. For example, <img src="image.jpg" alt="Description of image" /> is necessary.ConclusionSelf-closing tags are an essential part of HTML that simplify the markup structure and enhance code readability. Understanding their usage and the differences across HTML versions is crucial for web developers. By effectively using self-closing tags, developers can create cleaner and more efficient web pages. Comment More infoAdvertise with us Next Article What are Self Closing Tags in HTML? P pankaj2025 Follow Improve Article Tags : HTML Similar Reads What are physical tags in HTML? Physical Tags are used to indicate that how specific characters are to be formatted or indicated using HTML tags. Any physical style tag may contain any item allowed in text, including conventional text, images, line breaks, etc. Although each physical tag has a defined style, you can override that 5 min read What are logical tags in HTML ? Logical tags are used to tell the browser what kind of text is written inside the tags. They are different from physical tags because physical tags are used to decide the appearance of the text and do not provide any information about the text. Logical tags are used to indicate to the visually impai 5 min read What are HTML Tags ? HTML (HyperText Markup Language) is the standard markup language used to create the structure and layout of web pages. HTML documents consist of a series of elements, and these elements are defined using HTML tags. HTML tags are essential building blocks that define the structure and content of a we 2 min read What is grouping in HTML ? Grouping plays a vital role in our web page because it helps the developer to target specific classes and id which makes it easier to position, style, or manipulate the web page with the help of HTML, CSS, or JavaScript. Grouping can be performed with the help of various tags such as <div>, 2 min read What are the main functions of HTML DOM ? DOM or Document Object Model is an API(Application Programming Interface) that represents the HTML document in the form of the Tree structure such that programs can access and change the style and structure of the HTML document. The DOM object is automatically created by the web browser itself upon 3 min read What are the various formatting tags available in HTML ? As we know, HTML provides many predefined elements that are used to change the formatting of text. The formatting can be used to set the text styles (like â bold, italic, or emphasized, etc.), highlight the text, make text superscript and subscript, etc. In this article, we will discuss different fo 3 min read Explain use of Meta tags in HTML Meta Tag(<meta>) is a HTML component that gives the metadata about a HTML document. MetaData can be characterized as data that gives the data of different information or basic information about information. It is an empty tag, for example, it just has an initial tag and no end tag. They are al 4 min read Which tags contain both opening & closing tags in HTML ? HTML tags are markers that define the structure and content of web documents. They consist of angle brackets enclosing a tag name, such as <p> for paragraphs or <img> for images, and can include attributes for additional information. So to better understand which tags are opening and clo 5 min read Is HTML elements are same as tags or not ? HTML elements and tags are a lot different. Let's see what HTML elements and Tags actually are and their differences. The below image tells about HTML Elements and HTML Tags. HTML Tags: The starting and ending point parts of an HTML document are HTML Tags, which start with < (less than) and end w 2 min read What are various heading elements used to add heading in HTML ? An HTML heading tag is used to define the headings of a page. There are six levels of headings defined by HTML. These 6 heading elements are H1, H2, H3, H4, H5, and H6; with H1 being the highest level and H6 the least. In this article, we will discuss various heading elements used to add a heading i 2 min read Like