" 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:
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!