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

Detailed explanation of MySQL database index

Table of contents 1. Introduction to MySQL Index ...

Detailed explanation of several error handling when Nginx fails to start

When using Nginx as a Web server, I encountered t...

Steps to completely uninstall the docker image

1. docker ps -a view the running image process [r...

A complete tutorial on installing Ubuntu 20.04 using VMware virtual machine

Ubuntu is a relatively popular Linux desktop syst...

Detailed explanation of scheduled tasks and delayed tasks under Linux

at at + time at 17:23 at> touch /mnt/file{1..9...

Implementation of communication between Vue and Flask

Install axios and implement communication Here we...

Detailed explanation of vite2.0 configuration learning (typescript version)

introduce You Yuxi’s original words. vite is simi...

Shtml Concise Tutorial

Shtml and asp are similar. In files named shtml, s...

React realizes secondary linkage effect (staircase effect)

This article shares the specific code of React to...

Summary of Mysql slow query operations

Mysql slow query explanation The MySQL slow query...

Alibaba Cloud ESC Server Docker Deployment of Single Node Mysql

1. Download the accelerated version of msyql dock...

JavaScript ES new feature block scope

Table of contents 1. What is block scope? 2. Why ...

Teach you how to use Portainer to manage multiple Docker container environments

Table of contents Portainer manages multiple Dock...

CSS3 uses animation attributes to achieve cool effects (recommended)

animation-name animation name, can have multiple ...