XHTML tags have a closing tag

XHTML tags have a closing tag
<br />Original link: http://www.dudo.org/article.asp?id=253
There is a standard in the XHTML specification that "each XHTML tag has a closing tag". For elements in HTML that do not have an end tag, add a "/" before the end to close the tag. For example, the original writing method of the <img> tag in HTML is:
<img src="..." alt="...">
In XHTML, you should add a "/" before the ">" to close the tag. In order to prevent some old browsers from not recognizing this writing method, you should add a space before the "/" (HTML compatibility standard):
<img src="..." alt="..." />
This seems to mean that adding a "/" to the opening tag will close the tag. Especially for labels in the space, it seems to be more concise to use this method. For example,
<div class="clear"></div>
This is a piece of code that is often used in clearing floats (closing floating elements). Then it seems that it can be written as:
<div class="clear" />
Yes, the <div> element can be empty, and there is nothing wrong with writing it this way, but what consequences will arise if we use similar writing methods for other tags? To import an external JavaScript file into the <head>, we usually write:
<script type="text/javascript" src="..." language="javascript"></script>
Since there is no empty content, can we write
<script type="text/javascript" src="..." language="javascript" />
We found that this way of writing either does not work or results in errors in the browser. In most cases, the browser will think that the tag is not closed and mistakenly recognize that all content after <script> is Javascript code, which will cause an error. For example,
<textarea id="tt" cols="10" rows="8" />
If you run this code in a browser, you will find that starting from <textarea>, all the XHTML codes after that will be treated as the content of the text box and appear in the text box.
It seems that the paired tags that already exist in HTML4.0 must use the existing end tags in XHTML. So why is <div> okay? In fact, <div> is not allowed either, it’s just that <div> is not displayed so clearly in the browser. Writing methods such as <span /> are even more incorrect. First of all, <span> itself has a closing tag </span>. In addition, the content of the <span> tag cannot be blank (even pure spaces are not allowed). That is to say, except for tags such as <img>, <hr>, <link>, and <br>, which can be closed with “/”, other elements must use </...>, otherwise unexpected problems will occur.

<<:  How to install tomcat in docker and deploy the Springboot project war package

>>:  How to solve the problem that Seata cannot use MySQL 8 version

Recommend

MySQL 8.0.15 installation and configuration method graphic tutorial

This article records the installation and configu...

JS uses map to integrate double arrays

Table of contents Preface Simulating data Merged ...

The difference between br and br/ in HTML

answer from stackflow: Simply <br> is suffic...

Tutorial on installing MySQL with Docker and implementing remote connection

Pull the image docker pull mysql View the complet...

js simple and crude publish and subscribe sample code

What is Publish/Subscribe? Let me give you an exa...

Website background music implementation method

For individual webmasters, how to make their websi...

HTML optimization techniques you must know

To improve the performance of web pages, many dev...

Getting the creation time of a file under Linux and a practical tutorial

background Sometimes we need to get the creation ...

How to get the height of MySQL innodb B+tree

Preface The reason why MySQL's innodb engine ...

How to expand the disk size of a virtual machine

After Vmvare sets the disk size of the virtual ma...

Summary of several implementations of returning to the top in HTML pages

Recently, I need to make a back-to-top button whe...

JavaScript article will show you how to play with web forms

1. Introduction Earlier we introduced the rapid d...

Summary of WEBAPP development skills (notes for mobile website development)

1. To develop web responsively, the page must ada...

18 Web Usability Principles You Need to Know

You can have the best visual design skills in the...