Skip to content
Myr

Added an HTML FAQ document, first draft.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent f5fb457 · Browse files · 2 files+163 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+163 added−0 removed

  • other:+163 added−0 removed

2 files+163 added−0 removed

modified:docs/contents.rst.inc+1 added
38 unmodified lines
39.. toctree::40 :maxdepth: 24142 design43 htmlfaq44 extensiondev45 license46 upgrading47 changelog
added:docs/htmlfaq.rst+162 added
1HTML/XHTML FAQ2==============34The Flask documentation and example applications are using HTML5. You5will notice that in many situations when end tags are optional they are6not used to keep the HTML cleaner and also faster to load. Because there7is a lot of confusion about HTML and XHTML out there this document tries8to answer some of them.91011History on XHTML12----------------1314For a while it looked like HTML was about to be replaced by XHTML.15However barely any websites on the internet are actually real XHTML (which16means XHTML processed with XML rules). There are a couple of reasons why17this is the case. It mostly has to do with Internet Explorer which does18not accept the XHTML mimetype to switch the browser into XML mode.19However this is really easy to bypass but barely anyone does that. This20probably has to do with the fact that XHTML is really painful.2122Why is it painful? XML has very strict errorhandling. On a parsing error23the browser is supposed to show the user an ugly error message. Most of24the (X)HTML generation on the web is based on non-XML template engines25(such as Jinja, the one used in Flask) which do not protect you from26accidentally creating invalid HTML. There are XML based template engines27but they usually come with a larger runtime overhead and are not as28straightforward to use because they have to obey XML rules.2930Now the majority of users assumed they were using XHTML though. The31reasons for that is that they sticked an XHTML doctype on top of the32document and self-closed all necessary tags (``<br>`` becomes ``<br/>`` or33``<br></br>`` in XHTML). However even if the document properly validates34as XHTML there are still other things to keep in mind.3536XHTML also changes the way you work with JavaScript because you now have37to use the namespaced DOM interface with the XHTML namespace to query for38HTML elements.3940History of HTML541----------------4243HTML5 was started in 2004 under the name Web Applications 1.0 by the44WHATWG (Apple, Mozilla, Opera) and the idea was to write a new and45improved specification of HTML based on actual browser behaviour instead46of behaviour that exists on the paper but could not be implemented47because of backwards compatibility with the already existing web.4849For example in theory HTML4 ``<title/Hello/`` means exactly the same as50``<title>Hello</title>`` but because existing websites are using51pseudo-XHTML which uses the Slash in different ways, this could not be52implemented properly.5354In 2007 the specification was adopted as the basis of a new HTML55specification under the umbrella of the W3C. Currently it looks like56XHTML is losing traction, the XHTML 2 working group was disbanded and57HTML5 is being implemented by all major browser vendors.5859HTML versus XHTML60-----------------6162The following table gives you a quick overview of features available in63HTML 4.01, XHTML 1.1 and HTML5 (we are not looking at XHTML 1.0 here which64was superceeded by XHTML 1.1 or XHTML5 which is barely supported currently):6566+-----------------------------------------+----------+----------+----------+67| | HTML4.01 | XHTML1.1 | HTML5 |68+=========================================+==========+==========+==========+69| ``<tag/value/`` == ``<tag>value</tag>`` | |Y| [1]_ | |N| | |N| |70+-----------------------------------------+----------+----------+----------+71| ``<br/>`` supported | |N| | |Y| | |Y| [2]_ |72+-----------------------------------------+----------+----------+----------+73| ``<script/>`` supported | |N| | |Y| | |N| |74+-----------------------------------------+----------+----------+----------+75| might be served as `text/html` | |Y| | |N| [3]_ | |Y| |76+-----------------------------------------+----------+----------+----------+77| might be served as | |N| | |Y| | |N| |78| `application/xml+html` | | | |79+-----------------------------------------+----------+----------+----------+80| strict error handling | |N| | |Y| | |N| |81+-----------------------------------------+----------+----------+----------+82| inline SVG | |N| | |Y| | |Y| |83+-----------------------------------------+----------+----------+----------+84| inline MathML | |N| | |Y| | |Y| |85+-----------------------------------------+----------+----------+----------+86| ``<video>`` tag | |N| | |N| | |Y| |87+-----------------------------------------+----------+----------+----------+88| ``<audio>`` tag | |N| | |N| | |Y| |89+-----------------------------------------+----------+----------+----------+90| New semantical tags like ``<article>`` | |N| | |N| | |Y| |91+-----------------------------------------+----------+----------+----------+9293.. [1] Obscure feature inherited from SGML not supported by browsers94.. [2] For compatibility with XHTML generating server code for some95 tags such as ``<br>``. Should not be used.96.. [3] XHTML 1.0 is the last XHTML standard that allows to be served97 as `text/html` for backwards compatibility reasons.9899.. |Y| image:: _static/yes.png100 :alt: Yes101.. |N| image:: _static/no.png102 :alt: No103104What does Strict Mean?105----------------------106107HTML5 has strictly defined parsing rules, but it also specifies how a108browser should react to parsing errors. Some things people stumble upon109with HTML5 and older HTML standards is that browsers will accept some110things that still create the expected output even though it looks wrong111(eg: certain tags are missing or are not closed).112113Some of that is caused by the error handling browsers use if they114encounter a markup error, others are actually specified. The following115things are optional in HTML5 by standard and have to be supported by116browsers (and are supported):117118- ``<html>``, ``<head>`` or ``<body>``119- The closing tags for ``<p>``, ``<li>``, ``<dl>``, ``<dd>``, ``<tr>``,120 ``<td>``, ``<th>``, ``<tbody>``, ``<thead>``, ``<tfoot>``.121- quotes for attribtues if they contain no whitespace and some122 special chars that require quoting.123124This means the following piece of HTML5 is perfectly valid:125126.. sourcecode:: html127128 <!doctype html>129 <title>Hello HTML5</title>130 <div class=header>131 <h1>Hello HTML5</h1>132 <p class=tagline>HTML5 is awesome133 </div>134 <ul class=nav>135 <li><a href=/index>Index</a>136 <li><a href=/downloads>Downloads</a>137 <li><a href=/about>About</a>138 </ul>139 <div class=body>140 <h2>HTML5 is probably the future</h2>141 <p>142 There might be some other things around but in terms of143 browser vendor support, HTML5 is hard to beat.144 <dl>145 <dt>Key 1146 <dd>Value 1147 <dt>Key 2148 <dd>Value 2149 </dl>150 </div>151152153What should be used?154--------------------155156Currently the answer is HTML5. There are very few reasons to use XHTML157with the latest development. There are some companies successfully using158actual XML and XSLT on the client side with fallbacks to server side HTML4159generation for browsers not supporting XML and XSLT but but it's not very160common. Now that MathML and SVG landed in HTML5 and with the sad support161for XHTML in Internet Explorer and many JavaScript libraries for most162applications no reasons remain to use XHTML.