Skip to content
Myr

Applied leafstorm's html5faq patch

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 235d693 · Browse files · 2 files+115 added−71 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+115 added−71 removed

  • other:+115 added−71 removed

2 files+115 added−71 removed

modified:docs/htmlfaq.rst+114 added-71 removed
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.5may notice that in many situations, when end tags are optional they are6not used, so that the HTML is cleaner and faster to load. Because there7is much confusion about HTML and XHTML among developers, this document tries8to answer some of the major questions.91011History on XHTML11History of 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.14For a while, it appeared that HTML was about to be replaced by XHTML.15However, barely any websites on the Internet are actual XHTML (which is16HTML processed using XML rules). There are a couple of major reasons17why this is the case. One of them is Internet Explorer's lack of proper18XHTML support. The XHTML spec states that XHTML must be served with the MIME19type `application/xhtml+xml`, but Internet Explorer refuses to read files20with that MIME type.21While it is relatively easy to configure Web servers to serve XHTML properly,22few people do. This is likely because properly using XHTML can be quite23painful.2422Why is it painful? XML has very strict errorhandling. On a parsing error23the browser is supposed to show the user an ugly error message. Most of25One of the most important causes of pain is XML's draconian (strict and26ruthless) error handling. When an XML parsing error is encountered,27the browser is supposed to show the user an ugly error message, instead28of attempting to recover from the error and display what it can. Most of29the (X)HTML generation on the web is based on non-XML template engines30(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.31accidentally creating invalid XHTML. There are XML based template engines,32such as Kid and the popular Genshi, but they often come with a larger33runtime overhead and, are not as straightforward to use because they have34to obey XML rules.3530Now 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.36The majority of users, however, assumed they were properly using XHTML.37They wrote an XHTML doctype at the top of the document and self-closed all38the necessary tags (``<br>`` becomes ``<br/>`` or ``<br></br>`` in XHTML).39However, even if the document properly validates as XHTML, what really40determines XHTML/HTML processing in browsers is the MIME type, which as41said before is often not set properly. So the valid XHTML was being treated42as invalid HTML.4336XHTML 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.44XHTML also changed the way JavaScript is used. To properly work with XHTML,45programmers have to use the namespaced DOM interface with the XHTML46namespace to query for HTML elements.4748History of HTML549----------------5043HTML5 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.51Development of the HTML5 specification was started in 2004 under the name52"Web Applications 1.0" by the Web Hypertext Application Technology Working53Group, or WHATWG (which was formed by the major browser vendors Apple,54Mozilla, and Opera) with the goal of writing a new and improved HTML55specification, based on existing browser behaviour instead of unrealistic56and backwards-incompatible specifications.5749For 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.58For example, in HTML4 ``<title/Hello/`` theoretically parses exactly the59same as ``<title>Hello</title>``. However, since people were using60XHTML-like tags along the lines of ``<link />``, browser vendors implemented61the XHTML syntax over the syntax defined by the specification.6254In 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.63In 2007, the specification was adopted as the basis of a new HTML64specification under the umbrella of the W3C, known as HTML5. Currently,65it appears that XHTML is losing traction, as the XHTML 2 working group has66een disbanded and HTML5 is being implemented by all major browser vendors.6768HTML versus XHTML69-----------------7071The 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):72HTML 4.01, XHTML 1.1 and HTML5. (XHTML 1.0 is not included, as it was73superseded by XHTML 1.1 and the barely-used XHTML5.)7475.. tabularcolumns:: |p{9cm}|p{2cm}|p{2cm}|p{2cm}|7677+-----------------------------------------+----------+----------+----------+
4 unmodified lines
82| ``<br/>`` supported | |N| | |Y| | |Y| [2]_ |83+-----------------------------------------+----------+----------+----------+84| ``<script/>`` supported | |N| | |Y| | |N| |85+-----------------------------------------+----------+----------+----------+77| might be served as `text/html` | |Y| | |N| [3]_ | |Y| |86| should be served as `text/html` | |Y| | |N| [3]_ | |Y| |87+-----------------------------------------+----------+----------+----------+79| might be served as | |N| | |Y| | |N| |80| `application/xml+html` | | | |88| should be served as | |N| | |Y| | |N| |89| `application/xhtml+xml` | | | |90+-----------------------------------------+----------+----------+----------+91| strict error handling | |N| | |Y| | |N| |92+-----------------------------------------+----------+----------+----------+93| inline SVG | |N| | |Y| | |Y| |
3 unmodified lines
97| ``<video>`` tag | |N| | |N| | |Y| |98+-----------------------------------------+----------+----------+----------+99| ``<audio>`` tag | |N| | |N| | |Y| |100+-----------------------------------------+----------+----------+----------+92| New semantical tags like ``<article>`` | |N| | |N| | |Y| |101| New semantic tags like ``<article>`` | |N| | |N| | |Y| |102+-----------------------------------------+----------+----------+----------+10395.. [1] Obscure feature inherited from SGML not supported by browsers96.. [2] For compatibility with XHTML generating server code for some97 tags such as ``<br>``. Should not be used.104.. [1] This is an obscure feature inherited from SGML. It is usually not105 supported by browsers, for reasons detailed above.106.. [2] This is for compatibility with server code that generates XHTML for107 tags such as ``<br>``. It should not be used in new code.108.. [3] XHTML 1.0 is the last XHTML standard that allows to be served109 as `text/html` for backwards compatibility reasons.110111.. |Y| image:: _static/yes.png112 :alt: Yes113.. |N| image:: _static/no.png114 :alt: No115106What does Strict Mean?107----------------------116What does "strict" mean?117------------------------118109HTML5 has strictly defined parsing rules, but it also specifies how a110browser should react to parsing errors. Some things people stumble upon111with HTML5 and older HTML standards is that browsers will accept some112things that still create the expected output even though it looks wrong113(eg: certain tags are missing or are not closed).119HTML5 has strictly defined parsing rules, but it also specifies exactly120how a browser should react to parsing errors - unlike XHTML, which simply121states parsing should abort. Some people are confused by apparently122invalid syntax that still generates the expected results (for example,123missing end tags or unquoted attribute values).124115Some of that is caused by the error handling browsers use if they116encounter a markup error, others are actually specified. The following117things are optional in HTML5 by standard and have to be supported by118browsers (and are supported):125Some of these work because of the lenient error handling most browsers use126when they encounter a markup error, others are actually specified. The127following constructs are optional in HTML5 by standard, but have to be128supported by browsers:129120- ``<html>``, ``<head>`` or ``<body>``121- The closing tags for ``<p>``, ``<li>``, ``<dl>``, ``<dd>``, ``<tr>``,122 ``<td>``, ``<th>``, ``<tbody>``, ``<thead>``, ``<tfoot>``.123- quotes for attribtues if they contain no whitespace and some124 special chars that require quoting.130- Wrapping the document in an ``<html>`` tag131- Wrapping header elements in ``<head>`` or the body elements in132 ``<body>``133- Closing the ``<p>``, ``<li>``, ``<dl>``, ``<dd>``, ``<tr>``,134 ``<td>``, ``<th>``, ``<tbody>``, ``<thead>``, or ``<tfoot>`` tags.135- Quoting attributes, so long as they contain no whitespace or136 special characters (like ``<``, ``>``, ``'``, or ``"``).137- Requiring boolean attributes to have a value.138126This means the following piece of HTML5 is perfectly valid:139This means the following page in HTML5 is perfectly valid:140141.. sourcecode:: html142143 <!doctype html>
20 unmodified lines
164 </dl>165 </div>166167168New technologies in HTML5169-------------------------170171HTML5 adds many new features that make Web applications easier to write172and to use.173174- The ``<audio>`` and ``<video>`` tags provide a way to embed audio and175 video without complicated add-ons like QuickTime and Flask.176- Semantic elements like ``<article>``, ``<header>``, ``<nav>``, and177 ``<time>`` that make content easier to understand.178- The ``<canvas>`` tag, which supports a powerful drawing API, reducing179 the need for server-generated images to present data graphically.180- New form control types like ``<input type="date">`` that allow user181 agents to make entering and validating values easier.182- Advanced JavaScript APIs like Web Storage, Web Workers, Web Sockets,183 geolocation, and offline applications.184185Many other features have been added, as well. A good guide to new features186in HTML5 is Mark Pilgrim's soon-to-be-published book, `Dive Into HTML5`_.187Not all of them are supported in browsers yet, however, so use caution.188189_Dive into HTML5: http://www.diveintohtml5.org/190191What should be used?192--------------------193158Currently the answer is HTML5. There are very few reasons to use XHTML159with the latest development. There are some companies successfully using160actual XML and XSLT on the client side with fallbacks to server side HTML4161generation for browsers not supporting XML and XSLT but but it's not very162common. Now that MathML and SVG landed in HTML5 and with the sad support163for XHTML in Internet Explorer and many JavaScript libraries for most164applications no reasons remain to use XHTML.194Currently, the answer is HTML5. There are very few reasons to use XHTML195considering the latest developments in Web browsers. To summarize the196reasons given above:197198- Internet Explorer (which, sadly, currently leads in market share)199 has poor support for XHTML.200- Many JavaScript libraries also do not support XHTML, due to the more201 complicated namespacing API it requires.202- HTML5 adds several new features, including semantic tags and the203 long-awaited ``<audio>`` and ``<video>`` tags.204- It has the support of most browser vendors behind it.205- It is much easier to write, and more compact.206207For most applications, it is undoubtably better to use HTML5 than XHTML.
modified:AUTHORS+1 added
14 unmodified lines
15- Georg Brandl16- Justin Quick17- Kenneth Reitz18- Marian Sigler19- Matthew Frazier20- Ron DuPlain21- Sebastien Estienne22- Simon Sapin23- Stephane Wirtel
1 unmodified line