Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
HTML
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== SGML-based versus XML-based HTML === One difference in the latest{{when|date=March 2022}} HTML specifications lies in the distinction between the SGML-based specification and the XML-based specification. The XML-based specification is usually called [[XHTML]] to distinguish it clearly from the more traditional definition. However, the root element name continues to be "html" even in the XHTML-specified HTML. The W3C intended XHTML 1.0 to be identical to HTML 4.01 except where limitations of XML over the more complex SGML require workarounds. Because XHTML and HTML are closely related, they are sometimes documented in parallel. In such circumstances, some authors [[(X)HTML|conflate the two names]] as (X)HTML or X(HTML). Like HTML 4.01, XHTML 1.0 has three sub-specifications: strict, transitional, and frameset. Aside from the different opening declarations for a document, the differences between an HTML 4.01 and XHTML 1.0 document—in each of the corresponding DTDs—are largely syntactic. The underlying syntax of HTML allows many shortcuts that XHTML does not, such as elements with optional opening or closing tags, and even empty elements which must not have an end tag. By contrast, XHTML requires all elements to have an opening tag and a closing tag. XHTML, however, also introduces a new shortcut: an XHTML tag may be opened and closed within the same tag, by including a slash before the end of the tag like this: {{code|lang=html|code=<br/>}}. The introduction of this shorthand, which is not used in the SGML declaration for HTML 4.01, may confuse earlier software unfamiliar with this new convention. A fix for this is remove the slash preceding the closing angle bracket, as such: {{code|lang=html|code=<br>}}.<ref>{{citation|title=HTML Standard - The br Element|url=https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-br-element|publisher=WHATWG}}</ref> To understand the subtle differences between HTML and XHTML, consider the transformation of a valid and well-formed XHTML 1.0 document that adheres to Appendix C (see below) into a valid HTML 4.01 document. Making this translation requires the following steps: # '''The language for an element should be specified with a <code>lang</code> attribute rather than the XHTML <code>xml:lang</code> attribute.''' XHTML uses XML's built-in language-defining functionality attribute. # '''Remove the XML namespace (<code>xmlns=URI</code>).''' HTML has no facilities for namespaces. # '''Change the document type declaration''' from XHTML 1.0 to HTML 4.01. (see [[#Document type declaration|DTD section]] for further explanation). # If present, '''remove the XML declaration.''' (Typically this is: {{code|lang=xml|code=<?xml version="1.0" encoding="utf-8"?>}}). # '''Ensure that the document's MIME type is set to <code>text/html</code>.''' For both HTML and XHTML, this comes from the HTTP <code>Content-Type</code> header sent by the server. # '''Change the XML empty-element syntax to an HTML style empty element''' ({{code|lang=html|code=<br/>}} to {{code|lang=html|code=<br>}}). Those are the main changes necessary to translate a document from XHTML 1.0 to HTML 4.01. To translate from HTML to XHTML would also require the addition of any omitted opening or closing tags. Whether coding in HTML or XHTML it may just be best to always include the optional tags within an HTML document rather than remembering which tags can be omitted. A well-formed XHTML document adheres to all the syntax requirements of XML. A valid document adheres to the content specification for XHTML, which describes the document structure. The W3C recommends several conventions to ensure an easy migration between HTML and XHTML (see [https://www.w3.org/TR/xhtml1/#guidelines HTML Compatibility Guidelines]). The following steps can be applied to XHTML 1.0 documents only: * Include both <code>xml:lang</code> and <code>lang</code> attributes on any elements assigning language. * Use the empty-element syntax only for elements specified as empty in HTML. * Remove the closing slash in empty-element tags: for example {{code|lang=html|code=<br>}} instead of {{code|lang=html|code=<br/>}}. * Include explicit close tags for elements that permit content but are left empty (for example, {{code|lang=html|code=}}, not {{code|lang=html|code=<div />}}). * Omit the XML declaration. By carefully following the W3C's compatibility guidelines, a user agent should be able to interpret the document equally as HTML or XHTML. For documents that are XHTML 1.0 and have been made compatible in this way, the W3C permits them to be served either as HTML (with a <code>text/html</code> [[MIME type]]), or as XHTML (with an <code>application/xhtml+xml</code> or <code>application/xml</code> MIME type). When delivered as XHTML, browsers should use an XML parser, which adheres strictly to the XML specifications for parsing the document's contents.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)