Consent

This site uses third party services that need your consent.

Skip to content

Self-Closing HTML Tags: A Quick Guide

Self-closing tags in HTML are elements that do not require a closing tag. They are used for elements that do not contain content, such as images, line breaks, and horizontal rules.

Common Self-Closing Tags

  • <img>: Inserts an image.

  • <br>: Inserts a line break.

  • <hr>: Inserts a horizontal rule.

  • <input>: Creates various input fields, such as text boxes, checkboxes, and radio buttons.

  • <meta>: Provides metadata about the HTML page.

  • <source>: Specifies alternative media resources for <video> or <audio> elements.

  • <track>: Specifies timed text tracks for <video> or <audio> elements.

  • <embed>: Embeds external content (e.g., a plugin) within the HTML document.

  • <area>: Defines an area within an <img> element.

  • <link>: Defines a link between the current document and an external resource.

Note: While these tags are commonly used as self-closing, some older browsers may require a closing slash (/>) for all self-closing tags. However, this is no longer necessary in modern browsers.

Example:

<img src="image.jpg" alt="A beautiful image">
<br>
<hr>
<input type="text" name="name">
<meta charset="UTF-8">

Key Points:

  • No Content: Self-closing tags do not contain any content between the opening and closing tags.

  • Optional Closing Slash: While not strictly necessary in modern browsers, you can include a closing slash (/>) for consistency.

  • Accessibility: Ensure that self-closing tags are used appropriately to maintain accessibility and improve the user experience.

By understanding self-closing tags, you can write more efficient and readable HTML code.

---

Ready to master HTML and CSS? Get our comprehensive eBook.

Packed with easy-to-follow tutorials, practical examples, and expert tips, this eBook will guide you from the basics to advanced techniques. Click here to purchase your copy and kickstart your web development journey!

More articles

Get in touch

Please be informed that when you click the Send button Starfolk will process your personal data in accordance with our Privacy notice for the purpose of providing you with appropriate information.

Address

Remote

Monday 08:30 - 17:00
Tuesday 08:30 - 17:00
Wednesday 08:30 - 17:00
Thursday 08:30 - 17:00
Friday 08:30 - 17:00
Saturday Closed
Sunday Closed