shorttags.html 18.5 KB
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style type="text/css" media="all">
    @import "/QA/2006/01/blogstyle.css";
    </style>
    <meta name="keywords" content='html, implementation, qa, validator, w3c' />
    <meta name="description" content="Validation can be a very useful way to detect typos in markup... unless the typos disguise as shorttags, one of the little known features of HTML, valid but misunderstood by most browsers. Fortunately, there is hope, whether one prefers to author XHTML and never worry about shorttags, or stick to HTML." />
    <meta name="revision" content="$Id: shorttags.html,v 1.69 2011/12/16 02:58:36 gerald Exp $" />    
   <link rel="alternate" type="application/atom+xml" title="Atom" href="http://www.w3.org/QA/atom.xml" />
   <link rel="alternate" type="application/rss+xml" title="RSS 1.0" href="http://www.w3.org/QA/news.rss" />   
   <title>Shorttags - the odd side of HTML 4.01 - W3C Blog</title>

   <link rel="start" href="http://www.w3.org/QA/" title="Home" />
   <link rel="prev" href="http://www.w3.org/QA/2007/10/html-wg-at-tpac.html" title="HTML WG in Cambridge, USA - 8-10 November 2007" />
   <link rel="next" href="http://www.w3.org/QA/2007/10/validator-roadmap.html" title="Validator 0.8 getting stable - what next?" />

   <!--
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"
         xmlns:dc="http://purl.org/dc/elements/1.1/">
<rdf:Description
    rdf:about="http://www.w3.org/QA/2007/10/shorttags.html"
    trackback:ping="http://www.w3.org/QA/sununga/mt-tb.cgi/77"
    dc:title="Shorttags - the odd side of HTML 4.01"
    dc:identifier="http://www.w3.org/QA/2007/10/shorttags.html"
    dc:subject="HTML"
    dc:description="Validation can be a very useful way to detect typos in markup... unless the typos disguise as shorttags, one of the little known features of HTML, valid but misunderstood by most browsers. Fortunately, there is hope, whether one prefers to author XHTML and never worry about shorttags, or stick to HTML."
    dc:creator="olivier Théreaux"
    dc:date="2007-10-09T16:42:03+00:00" />
</rdf:RDF>
-->

    <!-- <script type="text/javascript" src="http://www.w3.org/QA/mt.js"></script>-->

</head>
<body class="layout-one-column">
      <div id="banner">
      <h1 id="title">
	<a href="http://www.w3.org/"><img height="48" alt="W3C" id="logo" src="http://www.w3.org/Icons/WWW/w3c_home_nb" /></a>
W3C Blog
</h1>
    </div>
    
    <ul class="navbar" id="menu">
        <li><strong><a href="/QA/" title="W3C Blog Home">[ W3C Blog ]</a></strong></li>
        <li><a href="/QA/Library/" title="Documents and Publications on Web and Quality">Documents</a></li>
        <li><a href="/QA/Tools/" accesskey="3" title="Validators and other Tools">Tools</a></li>
        <li><a href="/2007/12/qa-blog-help/index#feedback">Feedback</a></li>
    </ul>
<div id="searchbox">
<form method="get" action="http://www.google.com/custom" enctype="application/x-www-form-urlencoded">
<p id="formbox"><input type="text" size="15" class="textfield" name="q" accesskey="E" maxlength="255" /> <input type="submit" class="submitfield" value="Search" id="goButton" name="sa" accesskey="G" /> <input type="hidden" name="cof" value="T:black;LW:72;ALC:#ff3300;L:http://www.w3.org/Icons/w3c_home;LC:#000099;LH:48;BGC:white;AH:left;VLC:#660066;GL:0;AWFID:0b9847e42caf283e;" /><input type="hidden" id="searchW3C" name="sitesearch" checked="checked" value="www.w3.org/QA" /><input type="hidden" name="domains" value="www.w3.org/QA" /></p>
</form>
</div>


    <div id="main"><!-- This DIV encapsulates everything in this page - necessary for the positioning -->

                     <p class="content-nav">
                        <a href="http://www.w3.org/QA/2007/10/html-wg-at-tpac.html">&laquo; HTML WG in Cambridge, USA - 8-10 November 2007</a> |
                        <a href="http://www.w3.org/QA/">Main</a>
                        | <a href="http://www.w3.org/QA/2007/10/validator-roadmap.html">Validator 0.8 getting stable - what next? &raquo;</a>
                     </p>

                        <h2 class="entry-header">Shorttags - the odd side of HTML 4.01</h2>
                           <div class="entry-body">
                              <p>HTML 4.01 or XHTML 1.0? The choice between the two popular ways of authoring for the web seldom yields a clear answer: after all, the two languages share the same semantics, and the differences are mostly about the writing style.</p>

<p>Advocates of the XHTML style will hail the potential of XML for transformation and processing. Advocates of HTML 4.01 will generally reply that Internet Explorer, as of today, does not recognize the preferred media type for XHTML. As a result, most people serve XHTML in a way tantamount to serving tag soup to browsers: in that logic, using HTML 4.01 is the actually "strict" choice.</p>

<p>Both are quite correct, but for anyone authoring (X)HTML by hand, there is one very good reason, often overlooked, to prefer the XHTML syntax to the "classic" HTML one: shorttags.</p>

<h3>Shortwhat?</h3>

<p>Let's look at the following piece of HTML markup.</p>
<pre>
    &lt;p&lt;a href=&quot;/&quot;&gt;first part of the text&lt;/&gt; second part
</pre>

<p>Now for the surprising part: The above <a href="http://www.w3.org/TR/html401/appendix/notes.html#h-B.3.7">is proper HTML</a>. Valid, conformant, everything. It uses an ill-known feature of SGML called shorthand markup, which was authorized in HTML up to HTML 4.01. But what used to be a "cool" feature for SGML experts becomes a liability in HTML, where the construct is more likely to appear as a typo than as a conscious choice.</p>

<p>All could be fine if this form typo-that-happens-to-be-legal was properly implemented in contemporary HTML user-agents. It is not. In the example above, &lt;/&gt; is supposed to close the &lt;a&gt; element. In most browsers today, it does not, and the second part of the text will be part of the link, when it should not. <a href="http://qa-dev.w3.org/wmvs/HEAD/dev/tests/shorttags2.html">try it</a>. </p>

<h3>validation as helping tool</h3>

<p>This is reason enough for me, as clumsy author of HTML, to prefer the XHTML document types, notwithstanding all the media type debate: validation is an incentive to keep my code clean. XHTML forces me to close my elements, put my attributes behind quotes, and it won't let disruptive typos pass as valid.</p>

<p>That does not mean we are leaving HTML 4.01 authors in the awkward company of shorttags: since the <a href="http://www.w3.org/TR/html401/appendix/notes.html#h-B.3.7">HTML specification</a> lists these as not recommended, in the upcoming release of the <a href="http://validator.w3.org/" title="The W3C Markup Validation Service">Markup Validator</a>, detected usage of shorthand markup will be signaled as a warning. SGML hackers can still use it at their own risks. Others will be warned about, and advised to fix, their typos.</p>
                           </div>
                           <div id="more" class="entry-more">
                              
                           </div>
                       <p class="postinfo">Filed by <a href="http://www.w3.org/People/olivier/">olivier Théreaux</a> on October  9, 2007  4:42 PM in <a href="http://www.w3.org/QA/archive/w3cqa_news/bugs_life/">Bugs Life</a>, <a href="http://www.w3.org/QA/archive/technology/html/">HTML</a><br />
<span class="separator">|</span> <a class="permalink" href="http://www.w3.org/QA/2007/10/shorttags.html">Permalink</a>
                                 | <a href="http://www.w3.org/QA/2007/10/shorttags.html#comments">Comments (9)</a>
                                 | <a href="http://www.w3.org/QA/2007/10/shorttags.html#trackback">TrackBacks (0)</a>
</p>



<h3 class="comments-header" id="comments">Comments</h3>
<div class="comment" id="comment-72300">
<p class="comment-meta" id="c072300">
<span class="comment-meta-author"><strong>Anne van Kesteren </strong></span>
<span class="comment-meta-date"><a href="#c072300">#</a> 2007-10-09</span>
</p>
<div class="comment-bulk">
<p>This is simply a problem with HTML 4.01 not being realistic and the validator assuming it is (and being based on SGML tools). There's an HTML5 validator project that no longer has this problem and the same goes for the HTML5 specification which carefully defines a custom HTML syntax that is more realistic.</p>

</div>
</div>


<div class="comment" id="comment-72342">
<p class="comment-meta" id="c072342">
<span class="comment-meta-author"><strong>David Hammond </strong></span>
<span class="comment-meta-date"><a href="#c072342">#</a> 2007-10-09</span>
</p>
<div class="comment-bulk">
<p>This is precisely why I developed the HTML 4 Good Practice Checker (http://www.webdevout.net/test?html4-good-practice). This is a tool that modifies the way the W3C HTML Validator handles the document so that it enforces rules which normally aren't enforced. Using this tool on an HTML 4 document, you will see "validation errors" for things like shorttags, missing end tags (where allowed), unquoted attribute values, etc.</p>

</div>
</div>


<div class="comment" id="comment-72372">
<p class="comment-meta" id="c072372">
<span class="comment-meta-author"><strong>Daniel Aleksandersen </strong></span>
<span class="comment-meta-date"><a href="#c072372">#</a> 2007-10-09</span>
</p>
<div class="comment-bulk">
<p>The example code and example page works fine in Opera 9.5 alpha, build 1589. Says something about which browser is better. ;-)</p>

</div>
</div>


<div class="comment" id="comment-72415">
<p class="comment-meta" id="c072415">
<span class="comment-meta-author"><strong>olivier </strong></span>
<span class="comment-meta-date"><a href="#c072415">#</a> 2007-10-10</span>
</p>
<div class="comment-bulk">
<p>@David Hammond: Cool. Replacing the document type with a stricter DTD is quite a clever solution. The next version of the markup validator (coming tomorrow if all goes well) will give warnings for shorttag constructs, since they are, strictly speaking, allowed. Yielding errors for conforming but not recommended practices tends to make some people very, very angry ;)...</p>

<p>@Anne: Most HTML specifications were <a href="http://www.w3.org/TR/html401/intro/intro.html#h-2.2.1" rel="nofollow">standardizing the current state of development</a> in different browser projects, trying to bring consensus between all the players when implementations or goals differed.</p>

<p>Back to 1995:
HTML 2.0 becomes IETF Proposed Standard
This is an effort (started in 1994) to create a specification for interoperablility among implementations of HTML.</p>

<p>… Does that sound familiar? Not surprising, the development of the web is following a cycle. Right now we're in that part of the cycle where those wanting to make a clear map of existing implementations have the upper hand. Sooner or later, we'll get to the other side of the cycle, the innovation side:</p>

<p>HTML 3.0 internet draft
    "provides additional capabilities over previous versions such as tables, text flow around figures and math."</p>

<p>Since the days of early HTML however, Quality Assurance, and in particular the requirements for interoperability and implementation, have improved. Had this been around in the early days of the web, HTML4.01 would have been better, better implemented. The way HTML5 is being built from the current implementations has nothing to do with being realistic: it is - in a laudable way, and from the ground up - following a better, contemporary quality process.</p>

</div>
</div>


<div class="comment" id="comment-72591">
<p class="comment-meta" id="c072591">
<span class="comment-meta-author"><strong>David Hammond </strong></span>
<span class="comment-meta-date"><a href="#c072591">#</a> 2007-10-11</span>
</p>
<div class="comment-bulk">
<p>The warning is a great idea. I would, however, like to see a warning also given to people who use XHTML as text/html, informing them that typical browsers won't parse the document as XML, and there could be differences in parsing, CSS, and scripting depending on how the user agent treats it. Unfortunately, if you have your browser set up to parse all "XHTML" pages as real XML, most websites show significant problems, including the websites of many "standards experts". Check out this list: <a href="http://www.webdevout.net/articles/beware-of-xhtml#broken_xhtml" rel="nofollow">http://www.webdevout.net/articles/beware-of-xhtml#broken_xhtml</a></p>

<p>This is an issue that is not really understood by most web developers, and putting it right on the validation page would help bring it to more people's attention.</p>

</div>
</div>


<div class="comment" id="comment-72982">
<p class="comment-meta" id="c072982">
<span class="comment-meta-author"><strong>Anne van Kesteren </strong></span>
<span class="comment-meta-date"><a href="#c072982">#</a> 2007-10-12</span>
</p>
<div class="comment-bulk">
<p>olivier, sure, but implementations never implemented SGML so basing HTML on it doesn't seem like it ever reflected interoperability of anything.</p>

</div>
</div>


<div class="comment" id="comment-74265">
<p class="comment-meta" id="c074265">
<span class="comment-meta-author"><strong>Thomas Mayer </strong></span>
<span class="comment-meta-date"><a href="#c074265">#</a> 2007-10-21</span>
</p>
<div class="comment-bulk">
<p>I personally stay with HTML because Internet Explorer is not the only user agent that can't handle XHTML's mediatype. Lynx for example isn't able to as well.</p>

<p>Also sending XHTML as text/html defeats the purpose for me. And this is more problematic than even most "experts" think. Only recently I found out why DOM-1-Methods won't work in (real) XHTML.</p>

<p>Writing good HTML doesn't seem very hard to me. And the HTML 5 WG suggests validationg HTML 5 will be better than validation HTML 4 it seems the only proematic thing I can see with HTML 4 is going to go away.</p>

</div>
</div>


<div class="comment" id="comment-81368">
<p class="comment-meta" id="c081368">
<span class="comment-meta-author"><strong>Пётр Косаревский </strong></span>
<span class="comment-meta-date"><a href="#c081368">#</a> 2007-11-08</span>
</p>
<div class="comment-bulk">
<p>Latest available stable Opera version does not display the thing correctly (no line-break, no link).</p>

</div>
</div>


<div class="comment" id="comment-124271">
<p class="comment-meta" id="c124271">
<span class="comment-meta-author"><strong>4c </strong></span>
<span class="comment-meta-date"><a href="#c124271">#</a> 2008-03-21</span>
</p>
<div class="comment-bulk">
<p>
As tags can only be closed in the reverse order of being opened, tag names in end tags are useless in HTML.
</p>

<p><p>
I also think that every tag should be just that, and attributes should be instead expressed with child elements.
A location is always a location, for example take:</p>

<pre>
&lt;a href="gold.html">&lt;img src="gold.png"/>&lt;/a>
</pre>

<p>Would't this be more semantic and make more sense:</p>

<pre>
&lt;a>&lt;url>gold.html&lt;/>&lt;img>&lt;url>gold.png&lt;/>&lt;/>&lt;/>
</pre>
</p>
</div>
</div>



  <div class="comments-open" id="comments-open">
<h3 class="comments-open-header">Leave a comment</h3>

<div class="comments-open-moderated">
   <p>
   Note: this blog is intended to foster <strong>polite
   on-topic discussions</strong>. Comments failing these
   requirements and spam will not get published. Please,
   enter your real name and email address. Every
   individual comment is reviewed by the W3C staff.
   This may take some time, thank you for your patience.
   </p>
   <p>
   You can use the following HTML markup (a href, b, i, 
   br/, p, strong, em, ul, ol, li, blockquote, pre) 
   and/or <a href="http://daringfireball.net/projects/markdown/syntax">Markdown syntax</a>.</p>
</div>

<div id="comments-open-data">
<form method="post" action="http://www.w3.org/QA/sununga/beach.pl" id="comments-form">
<h4>Your comment</h4>
<div id="comments-open-text">
  <textarea id="comment-text" name="text" rows="20" cols="100"></textarea><br />
<label for="comment-text">Write your comment text here. Remember, keep the discussion on topic and courteous.</label>
</div>

<h4>About you</h4>
<div id="comment-form-name">
  <input type="hidden" name="static" value="1" />
<input type="hidden" name="entry_id" value="85" />
<input type="hidden" name="__lang" value="en" /> 
<label for="comment-author">Your Name</label>
<input id="comment-author" name="author" size="30" value="" />
</div>
<div id="comment-form-email">
<label for="comment-email">Your Email Address</label>
<input id="comment-email" name="email" size="30" value="" />
</div>

<div id="comments-open-footer">
<input type="submit" accesskey="s" name="post" id="comment-submit" value="Submit" />

</div>
</form>
</div>
</div>



<p id="gentime">This page was last generated on $Date: 2011/12/16 02:58:36 $</p> 

      </div><!-- End of "main" DIV. -->

<address>

This blog is written by W3C staff and working group participants,<br />
&nbsp;and maintained by <a href="/People/CMercier/">Coralie Mercier</a>.<br />
Authorized parties may <a href="/QA/new">log in</a> to create a new entry.<br/>
<span id="poweredby">Powered by Movable Type, magpierss and a lot of Web Technology</span>
    </address>


    
    <p class="copyright">
      <a rel="Copyright" href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> &copy; 1994-2011
      <a href="http://www.w3.org/"><acronym title="World Wide Web Consortium">W3C</acronym></a>&reg;
      (<a href="http://www.csail.mit.edu/"><acronym title="Massachusetts Institute of Technology">MIT</acronym></a>,
      <a href="http://www.ercim.eu/"><acronym title="European Research Consortium for Informatics and Mathematics">ERCIM</acronym></a>,
      <a href="http://www.keio.ac.jp/">Keio</a>),
      All Rights Reserved.
      W3C <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
      <a href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>,
      <a rel="Copyright" href="http://www.w3.org/Consortium/Legal/copyright-documents">document use</a>
      and <a rel="Copyright" href="http://www.w3.org/Consortium/Legal/copyright-software">software licensing</a>
      rules apply. Your interactions with this site are in accordance
      with our <a href="http://www.w3.org/Consortium/Legal/privacy-statement#Public">public</a> and
      <a href="http://www.w3.org/Consortium/Legal/privacy-statement#Members">Member</a> privacy
      statements.
    </p>

  </body>
</html>