"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Is \"\" a Valid Way to Close an HTML Span Tag?

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

Published on 2024-11-18
Browse:642

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/).
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3