Home >Web Front-end >CSS Tutorial >Is \'\' a Valid Way to Close an HTML Span Tag?

Is \'\' a Valid Way to Close an HTML Span Tag?

DDD
DDDOriginal
2024-11-02 17:54:29995browse

Is " a Valid Way to Close an HTML Span Tag? " />" a Valid Way to Close an HTML Span Tag? " />

Can an HTML Span Be Closed with ""?

The validity of closing an HTML span with "" hinges on the doctype used.

XHTML

In XHTML, which adheres to XML standards, all major browsers recognize self-closing tags like "". For instance, consider the following valid XHTML code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
    </head>
    <body>
        <h2>Will test page</h2>
        <p>some stuff <span class="drop" /></p>
    </body>
</html>

HTML (Non-XHTML)

In contrast, when using HTML without the XHTML doctype, "" is not a valid self-closing tag. Take this HTML example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
    </head>
    <body>
        <h2>Will test page</h2>
        <p>some stuff <span class="drop" /></p>
    </body>
</html>

This code will not validate because spans must be properly closed with "".

Additional Notes:

  • Browsers only ensure correct interpretation of self-closing tags if the mime type of the page is "text/xml" or "application/xhtml xml". For most web pages, served as "text/html", see the references for approved self-closing tags.
  • Helpful references: [W3C Validator](https://validator.w3.org/), [XHTML vs. HTML](https://www.w3.org/TR/xhtml11/).

The above is the detailed content of Is '' a Valid Way to Close an HTML Span Tag?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn