Programming 2 min read

HTML5 Self Closing Tags

Photo · Florian Olivo on Unsplash
On this page

HTML is a markup language used for creating web pages. In HTML, there are two types of tags: opening tags and closing tags. Opening tags begin with a less-than symbol (<) followed by the tag name, and closing tags begin with a less-than symbol followed by a forward slash (/) and the tag name. However, in HTML5, there are certain tags that can be self-closing, meaning they don’t require a separate closing tag. In this article, we will discuss self-closing tags in HTML5.

What are self-closing tags?

#

Self-closing tags are HTML tags that don’t require a separate closing tag. Instead, they are written as a single tag with a forward slash (/) at the end. Here’s an example of a self-closing tag in HTML5:

html
<img src="image.jpg" alt="an image" />

In this example, the <img> tag is a self-closing tag. It’s used to display an image on a web page and doesn’t require a separate closing tag.

Which tags are self-closing in HTML5?

#

There are several tags that can be self-closing in HTML5. Here are some examples:

  • <area>
  • <base>
  • <br>
  • <col>
  • <embed>
  • <hr>
  • <img>
  • <input>
  • <link>
  • <meta>
  • <param>
  • <source>
  • <track>
  • <wbr>

All of these tags can be written as self-closing tags in HTML5.

Why use self-closing tags?

#

Self-closing tags can be useful for a few reasons. Firstly, they can make your code more concise and easier to read. For example, instead of writing:

html
<br></br>

You can simply write:

html
<br />

Secondly, self-closing tags can help prevent errors in your HTML code. If you forget to close a tag, your web page may not render correctly or may not work at all. By using self-closing tags, you can avoid this issue altogether.

Conclusion

#

Self-closing tags are a useful feature of HTML5. By knowing which tags can be self-closing and when to use them, you can write cleaner, more efficient HTML code. Remember to use self-closing tags when appropriate, but don’t overuse them, as some tags still require a separate closing tag.

More on this topic:

#
  1. https://www.tutorialstonight.com/self-closing-tags-in-html.php
  2. https://stackoverflow.com/questions/3558119/are-non-void-self-closing-tags-valid-in-html5
Share Suggest an edit

Suggest an edit

HTML5 Self Closing Tags

Your suggestion and any name or email you give are stored and emailed to the author. Privacy

Read it in your terminal
curl -sL florea.xyz/html5-self-closing-tag.md
View as Markdown
NORMAL html5-self-closing-tag.md [programming] utf-8 · unix · 2 min read Top
Discussion · 0

Got it working, or hit a snag?

Share your setup, a fix or a question. Markdown and code blocks work.

How comments and emails are handled: Privacy.