Self-Closing Tags

Unlike normal tags, self-closing tags do not require a closing tag.

They are used for elements that do not enclose textual content.

These tags are often used to insert elements into the page, such as an image or a horizontal line, without needing to contain other elements or text.

Example:

  • The `<img>` tag to insert an image. It requires attributes like `src` (image source) and `alt` (alternative text for the image), but no closing tag.


    Example code :

    <img src="image.jpg" alt="Description of the image">

  • Another common example is the <br> tag for a line break.


    Example code :

    Here is a line.<br>
    And here's a new line after the jump.