Hướng dẫn self-closing tags in html
In this tutorial, you will learn about self closing tags in HTML, how to use them, and close the self closing tag. Also, you will go through various self closing tags with descriptions and examples. Show HTML Self Closing TagA self closing tags in HTML are the type of HTML tags that need not to be closed manually by its closing tag, which means there is no saperate closing tag for it as . A few examples of self closing tags are
None of the self closing tags in the above code snippets has content within them, nor do they have any child
nodes. Here are of closing tags in HTML (tags that need to be closed) are ... In HTML, closing a self closing tag with its
closing tag is invalid. For example, closing a tag like is not valid. But the question is do we need to close these tags by using /> at the end of the tag. i.e The fact is there is no need to close self closing tags by a slash /> at the end of the tag. Although many people use it but there is no meaning of slash at the end of the start tag even though you use it is ignored by the browsers. But when using XHTML it is the rule to close the self closing tag
by a slash at the end, so for the convenience of XHTML users HTML also allows closing tag like XHTML in HTML but simply ignores the slash. Even if you close the tag browser remove the slashes and then render the element. You can see the picture below to understand. Note - Even if the browser ignores the closing slash in void tags, it's
good practice to close it because: Here is a list of all the self closing tags in HTML with little description of all. Non of self closing tags can have content or child node. The br tag
Closing tag in HTML exampleClosing tags are the tags in HTML that need to be closed. These have a starting tag and an ending tag. The ending tag is the closing tag. For example, the opening tag for the paragraph tag is and the closing tag is . The closing tags are the same as the opening tags except that the closing tag has a forward slash (/) just before the tag name.
Even if you don't close the closing tag, they may be still be looking fine in the browser but it is not a good practice to leave the closing tag open. Frequently Asked Questions
Self closing tags VS closing tags
Conclusionself closing tags are empty tags that do not have content. They do not need to be closed however if self closed by /> then ignored by browsers.
|