<p>Sentences used this time: <a href="https://github.com/hail2u/html-best-practices">https://github.com/hail2u/html-best-practices</a></p>
<hr />
<blockquote cite="https://github.com/hail2u/html-best-practices">
  <h1 id="htmlbestpractices">HTML Best Practices</h1>
  <p>For writing maintainable and scalable HTML documents</p>
  <div>

    <!-- Added code -->
    <details class="_toc" open hidden>
      <summary>Table of contents</summary>
    </details>
    <!-- / Added code -->

    <h2 id="general">General</h2>
    <h3>Start with DOCTYPE</h3>
    <p>DOCTYPE is required for activating no-quirks mode.</p>
    <p>Bad:</p>
    <pre><code>&lt;html&gt;
  ...
&lt;/html&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
  ...
&lt;/html&gt;
</code></pre>
    <h3>Don't use legacy or obsolete DOCTYPE</h3>
    <p>DOCTYPE is not for DTD anymore, be simple.</p>
    <p>Bad:</p>
    <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd"&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;!DOCTYPE html&gt;
</code></pre>
    <h3>Don't use XML Declaration</h3>
    <p>Are you sure you want to write XHTML?</p>
    <p>Bad:</p>
    <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
&lt;!DOCTYPE html&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;!DOCTYPE html&gt;
</code></pre>
    <h3>Don't use character references as much as possible</h3>
    <p>If you write an HTML document with UTF-8, almost all characters (including
      Emoji) can be written directly.</p>
    <p>Bad:</p>
    <pre><code>&lt;p&gt;&lt;small&gt;Copyright &amp;copy; 2014 W3C&lt;sup&gt;&amp;reg;&lt;/sup&gt;&lt;/small&gt;&lt;/p&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;p&gt;&lt;small&gt;Copyright c 2014 W3C&lt;sup&gt;R&lt;/sup&gt;&lt;/small&gt;&lt;/p&gt;
</code></pre>
    <h3>Escape <code>&amp;</code>, <code>&lt;</code>, <code>&gt;</code>, <code>"</code>, and <code>'</code> with named character references</h3>
    <p>These characters should escape always for a bug-free HTML document.</p>
    <p>Bad:</p>
    <pre><code>&lt;h1&gt;The "&amp;" character&lt;/h1&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;h1&gt;The &amp;quot;&amp;amp;&amp;quot; character&lt;/h1&gt;
</code></pre>
    <h3>Use numeric character references for control or invisible characters</h3>
    <p>These characters are easily mistaken for another character. And also spec does
      not guarantee to define a human readable name for these characters.</p>
    <p>Bad:</p>
    <pre><code>&lt;p&gt;This book can read in 1 hour.&lt;/p&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;p&gt;This book can read in 1&amp;#xA0;hour.&lt;/p&gt;
</code></pre>
    <h3>Put white spaces around comment contents</h3>
    <p>Some characters cannot be used immediately after comment open or before comment
      close.</p>
    <p>Bad:</p>
    <pre><code>&lt;!--This section is non-normative--&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;!-- This section is non-normative --&gt;
</code></pre>
    <h3>Don't omit closing tag</h3>
    <p>I think you don't understand a rule for omitting closing tag.</p>
    <p>Bad:</p>
    <pre><code>&lt;html&gt;
  &lt;body&gt;
    ...
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;html&gt;
  &lt;body&gt;
    ...
  &lt;/body&gt;
&lt;/html&gt;
</code></pre>
    <h3>Don't mix empty element format</h3>
    <p>Consistency is a key for readability.</p>
    <p>Bad:</p>
    <pre><code>&lt;img alt="HTML Best Practices" src="/img/logo.png"&gt;
&lt;hr /&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;img alt="HTML Best Practices" src="/img/logo.png"&gt;
&lt;hr&gt;
</code></pre>
    <h3>Don't put white spaces around tags and attribute values</h3>
    <p>There is no reason for doing this.</p>
    <p>Bad:</p>
    <pre><code>&lt;h1 class=" title " &gt;HTML Best Practices&lt;/h1&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;h1 class="title"&gt;HTML Best Practices&lt;/h1&gt;
</code></pre>
    <h3>Don't mix character cases</h3>
    <p>It gives a consistency also.</p>
    <p>Bad:</p>
    <pre><code>&lt;a HREF="#general"&gt;General&lt;/A&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;a href="#general"&gt;General&lt;/a&gt;
</code></pre>
    <p>Also Good:</p>
    <pre><code>&lt;A HREF="#general"&gt;General&lt;/A&gt;
</code></pre>
    <h3>Don't mix quotation marks</h3>
    <p>Same as above.</p>
    <p>Bad:</p>
    <pre><code>&lt;img alt="HTML Best Practices" src='/img/logo.jpg'&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;img alt="HTML Best Practices" src="/img/logo.jpg"&gt;
</code></pre>
    <h3>Don't separate attributes with two or more white spaces</h3>
    <p>Your weird formatting rule confuses someone.</p>
    <p>Bad:</p>
    <pre><code>&lt;input   name="q"  type="search"&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;input name="q" type="search"&gt;
</code></pre>
    <h3>Omit boolean attribute value</h3>
    <p>It's easy to write, isn't it?</p>
    <p>Bad:</p>
    <pre><code>&lt;audio autoplay="autoplay" src="/audio/theme.mp3"&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;audio autoplay src="/audio/theme.mp3"&gt;
</code></pre>
    <h3>Omit namespaces</h3>
    <p>SVG and MathML can be used directly in an HTML document.</p>
    <p>Bad:</p>
    <pre><code>&lt;svg xmlns="http://www.w3.org/2000/svg"&gt;
  ...
&lt;/svg&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;svg&gt;
  ...
&lt;/svg&gt;
</code></pre>
    <h3>Don't use XML attributes</h3>
    <p>We write an HTML document.</p>
    <p>Bad:</p>
    <pre><code>&lt;span lang="ja" xml:lang="ja"&gt;...&lt;/span&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;span lang="ja"&gt;...&lt;/span&gt;
</code></pre>
    <h3>Don't mix <code>data-*</code>, Microdata, and RDFa Lite attributes with common attributes</h3>
    <p>A tag string can be very complicated. This simple rule helps reading such tag
      string.</p>
    <p>Bad:</p>
    <pre><code>&lt;img alt="HTML Best Practices" data-height="31" data-width="88" itemprop="image" src="/img/logo.png"&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;img alt="HTML Best Practices" src="/img/logo.png" data-width="88" data-height="31" itemprop="image"&gt;
</code></pre>
    <h3>Prefer default implicit ARIA semantics</h3>
    <p>Some elements have an ARIA <code>role</code> implicitly in an HTML document, don't specify them.</p>
    <p>Bad:</p>
    <pre><code>&lt;nav role="navigation"&gt;
  ...
&lt;/nav&gt;

&lt;hr role="separator"&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;nav&gt;
  ...
&lt;/nav&gt;

&lt;hr&gt;
</code></pre>
    <h2 id="therootelement">The root element</h2>
    <h3>Add <code>lang</code> attribute</h3>
    <p><code>lang</code> attribute will help translating an HTML document.</p>
    <p>Bad:</p>
    <pre><code>&lt;html&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;html lang="en-US"&gt;
</code></pre>
    <h3>Keep <code>lang</code> attribute value as short as possible</h3>
    <p>Japanese is only used in Japan. So country code is not necessary.</p>
    <p>Bad:</p>
    <pre><code>&lt;html lang="ja-JP"&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;html lang="ja"&gt;
</code></pre>
    <h3>Avoid <code>data-*</code> as much as possible</h3>
    <p>An appropriate attribute can be handled properly by browsers.</p>
    <p>Bad:</p>
    <pre><code>&lt;span data-language="french"&gt;chemises&lt;/span&gt;
...
&lt;strong data-type="warning"&gt;Do not wash!&lt;/strong&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;span title="French"&gt;&lt;span lang="fr"&gt;chemises&lt;/span&gt;&lt;/span&gt;
...
&lt;strong class="warning"&gt;Do not wash!&lt;/strong&gt;
</code></pre>
    <h2 id="documentmetadata">Document metadata</h2>
    <h3>Add <code>title</code> element</h3>
    <p>A value for <code>title</code> element is used by various application not only a browser.</p>
    <p>Bad:</p>
    <pre><code>&lt;head&gt;
  &lt;meta charset="UTF-8"&gt;
&lt;/head&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;head&gt;
  &lt;meta charset="UTF-8"&gt;
  &lt;title&gt;HTML Best Practices&lt;/title&gt;
&lt;/head&gt;
</code></pre>
    <h3>Don't use <code>base</code> element</h3>
    <p>An absolute path or URL is safer for both developers and users.</p>
    <p>Bad:</p>
    <pre><code>&lt;head&gt;
  ...
  &lt;base href="/blog/"&gt;
  &lt;link href="hello-world" rel="canonical"&gt;
  ...
&lt;/head&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;head&gt;
  ...
  &lt;link href="/blog/hello-world" rel="canonical"&gt;
  ...
&lt;/head&gt;
</code></pre>
    <h3>Specify MIME type of minor linked resources</h3>
    <p>This is a hint how application handles this resource.</p>
    <p>Bad:</p>
    <pre><code>&lt;link href="/pdf" rel="alternate"&gt;
&lt;link href="/feed" rel="alternate"&gt;
&lt;link href="/css/screen.css" rel="stylesheet"&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;link href="/pdf" rel="alternate" type="application/pdf"&gt;
&lt;link href="/feed" rel="alternate" type="application/rss+xml"&gt;
&lt;link href="/css/screen.css" rel="stylesheet"&gt;
</code></pre>
    <h3>Don't link to <code>favicon.ico</code></h3>
    <p>Almost all browsers fetch <code>/favicon.ico</code> automatically and asynchronously.</p>
    <p>Bad:</p>
    <pre><code>&lt;link href="/favicon.ico" rel="icon" type="image/vnd.microsoft.icon"&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;!-- Place `favicon.ico` in the root directory. --&gt;
</code></pre>
    <h3>Add <code>apple-touch-icon</code> link</h3>
    <p>A default request path for touch icon was changed suddenly.</p>
    <p>Bad:</p>
    <pre><code>&lt;!-- Hey Apple! Please download `/apple-touch-icon.png`! --&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;link href="/apple-touch-icon.png" rel="apple-touch-icon"&gt;
</code></pre>
    <h3>Add <code>title</code> attribute to alternate stylesheets</h3>
    <p>A human readable label helps people selecting proper stylesheet.</p>
    <p>Bad:</p>
    <pre><code>&lt;link href="/css/screen.css" rel="stylesheet"&gt;
&lt;link href="/css/high-contrast.css" rel="alternate stylesheet"&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;link href="/css/screen.css" rel="stylesheet"&gt;
&lt;link href="/css/high-contrast.css" rel="alternate stylesheet" title="High contrast"&gt;
</code></pre>
    <h3>For URL, use <code>link</code> element</h3>
    <p>A value of <code>href</code> attribute can be resolved as URL.</p>
    <p>Bad:</p>
    <pre><code>&lt;section itemscope itemtype="http://schema.org/BlogPosting"&gt;
  &lt;meta content="https://example.com/blog/hello" itemprop="url"&gt;
  ...
&lt;/section&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;section itemscope itemtype="http://schema.org/BlogPosting"&gt;
  &lt;link href="/blog/hello" itemprop="url"&gt;
  ...
&lt;/section&gt;
</code></pre>
    <h3>Specify document character encoding</h3>
    <p>UTF-8 is not default in all browsers yet.</p>
    <p>Bad:</p>
    <pre><code>&lt;head&gt;
  &lt;title&gt;HTML Best Practices&lt;/title&gt;
&lt;/head&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;head&gt;
  &lt;meta charset="UTF-8"&gt;
  &lt;title&gt;HTML Best Practices&lt;/title&gt;
&lt;/head&gt;
</code></pre>
    <h3>Don't use legacy character encoding format</h3>
    <p>HTTP headers should be specified by a server, be simple.</p>
    <p>Bad:</p>
    <pre><code>&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;meta charset="UTF-8"&gt;
</code></pre>
    <h3>Specify character encoding at first</h3>
    <p>Spec requires the character encoding is specified within the first 1024 bytes of
      the document.</p>
    <p>Bad:</p>
    <pre><code>&lt;head&gt;
  &lt;meta content="width=device-width" name="viewport"&gt;
  &lt;meta charset="UTF-8"&gt;
  ...
&lt;/head&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;head&gt;
  &lt;meta charset="UTF-8"&gt;
  &lt;meta content="width=device-width" name="viewport"&gt;
  ...
&lt;/head&gt;
</code></pre>
    <h3>Use UTF-8</h3>
    <p>With UTF-8, you are free to use Emoji.</p>
    <p>Bad:</p>
    <pre><code>&lt;meta charset="Shift_JIS"&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;meta charset="UTF-8"&gt;
</code></pre>
    <h3>Omit <code>type</code> attribute for CSS</h3>
    <p>In HTML, default <code>type</code> attribute's value of <code>style</code> element is <code>text/css</code>.</p>
    <p>Bad:</p>
    <pre><code>&lt;style type="text/css"&gt;
  ...
&lt;/style&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;style&gt;
  ...
&lt;/style&gt;
</code></pre>
    <h3>Don't comment out contents of <code>style</code> element</h3>
    <p>This ritual is for the old browser.</p>
    <p>Bad:</p>
    <pre><code>&lt;style&gt;
&lt;!--
  ...
  --&gt;
&lt;/style&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;style&gt;
  ...
&lt;/style&gt;
</code></pre>
    <h3>Don't mix tag for CSS and JavaScript</h3>
    <p>Sometimes <code>script</code> element blocks DOM construction.</p>
    <p>Bad:</p>
    <pre><code>&lt;script src="/js/jquery.min.js"&gt;&lt;/script&gt;
&lt;link href="/css/screen.css" rel="stylesheet"&gt;
&lt;script src="/js/main.js"&gt;&lt;/script&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;link href="/css/screen.css" rel="stylesheet"&gt;
&lt;script src="/js/jquery.min.js"&gt;&lt;/script&gt;
&lt;script src="/js/main.js"&gt;&lt;/script&gt;
</code></pre>
    <p>Also good:</p>
    <pre><code>&lt;script src="/js/jquery.min.js"&gt;&lt;/script&gt;
&lt;script src="/js/main.js"&gt;&lt;/script&gt;
&lt;link href="/css/screen.css" rel="stylesheet"&gt;
</code></pre>
    <h2 id="sections">Sections</h2>
    <h3>Add <code>body</code> element</h3>
    <p>Sometimes <code>body</code> element is complemented in unexpected position by a browser.</p>
    <p>Bad:</p>
    <pre><code>&lt;html&gt;
  &lt;head&gt;
    ...
  &lt;/head&gt;
  ...
&lt;/html&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;html&gt;
  &lt;head&gt;
    ...
  &lt;/head&gt;
  &lt;body&gt;
    ...
  &lt;/body&gt;
&lt;/html&gt;
</code></pre>
    <h3>Forget about <code>hgroup</code> element</h3>
    <p>This element is not used very much.</p>
    <p>Bad:</p>
    <pre><code>&lt;hgroup&gt;
  &lt;h1&gt;HTML Best Practices&lt;/h1&gt;
  &lt;h2&gt;For writing maintainable and scalable HTML documents.&lt;/h2&gt;
&lt;/hgroup&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;h1&gt;HTML Best Practices&lt;/h1&gt;
&lt;p&gt;For writing maintainable and scalable HTML documents.&lt;/p&gt;
</code></pre>
    <h3>Use <code>address</code> element only for contact information</h3>
    <p><code>address</code> element is for email address, social network account, street address,
      telephone number, or something you can get in touch with.</p>
    <p>Bad:</p>
    <pre><code>&lt;address&gt;No rights reserved.&lt;/address&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;address&gt;Contact: &lt;a href="https://twitter.com/hail2u_"&gt;Kyo Nagashima&lt;/a&gt;&lt;/address&gt;
</code></pre>
    <h2 id="groupingcontent">Grouping content</h2>
    <h3>Don't start with newline in <code>pre</code> element</h3>
    <p>A first newline will ignored in the browsers, but second and later are rendered.</p>
    <p>Bad:</p>
    <pre><code>&lt;pre&gt;
&amp;lt;!DOCTYPE html&amp;gt;
&lt;/pre&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;pre&gt;&amp;lt;!DOCTYPE html&amp;gt;
&lt;/pre&gt;
</code></pre>
    <h3>Use appropriate element in <code>blockquote</code> element</h3>
    <p><code>blockquote</code> element's content is a quote, not a chunks of characters.</p>
    <p>Bad:</p>
    <pre><code>&lt;blockquote&gt;For writing maintainable and scalable HTML documents.&lt;/blockquote&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;blockquote&gt;
  &lt;p&gt;For writing maintainable and scalable HTML documents.&lt;/p&gt;
&lt;/blockquote&gt;
</code></pre>
    <h3>Don't include attribution directly in <code>blockquote</code> element</h3>
    <p><code>blockquote</code> element's content is a quote.</p>
    <p>Bad:</p>
    <pre><code>&lt;blockquote&gt;
  &lt;p&gt;For writing maintainable and scalable HTML documents.&lt;/p&gt;

  &lt;p&gt;? HTML Best Practices&lt;/p&gt;
&lt;/blockquote&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;blockquote&gt;
  &lt;p&gt;For writing maintainable and scalable HTML documents.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;? HTML Best Practices&lt;/p&gt;
</code></pre>
    <p>Also good:</p>
    <pre><code>&lt;figure&gt;
  &lt;blockquote&gt;
    &lt;p&gt;For writing maintainable and scalable HTML documents.&lt;/p&gt;
  &lt;/blockquote&gt;

  &lt;figcaption&gt;? HTML Best Practices&lt;/figcaption&gt;
&lt;/figure&gt;
</code></pre>
    <h3>Write one list item per line</h3>
    <p>Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong
      line is hard toooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo read.</p>
    <p>Bad:</p>
    <pre><code>&lt;ul&gt;
  &lt;li&gt;General&lt;/li&gt;&lt;li&gt;The root Element&lt;/li&gt;&lt;li&gt;Sections&lt;/li&gt;...
&lt;/ul&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;ul&gt;
  &lt;li&gt;General&lt;/li&gt;
  &lt;li&gt;The root Element&lt;/li&gt;
  &lt;li&gt;Sections&lt;/li&gt;
  ...
&lt;/ul&gt;
</code></pre>
    <h3>Use <code>type</code> attribute for <code>ol</code> element</h3>
    <p>Sometimes marker referenced by the contents in the near. If you change marker
      with <code>type</code> attribute, you will be safe to reference.</p>
    <p>Bad:</p>
    <pre><code>&lt;head&gt;
  &lt;style&gt;
    .toc {
      list-style-type: upper-roman;
    }
  &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;ol class="toc"&gt;
    &lt;li&gt;General&lt;/li&gt;
    &lt;li&gt;The root Element&lt;/li&gt;
    &lt;li&gt;Sections&lt;/li&gt;
    ...
  &lt;/ol&gt;
&lt;/body&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;body&gt;
  &lt;ol type="I"&gt;
    &lt;li&gt;General&lt;/li&gt;
    &lt;li&gt;The root Element&lt;/li&gt;
    &lt;li&gt;Sections&lt;/li&gt;
    ...
  &lt;/ol&gt;
&lt;/body&gt;
</code></pre>
    <h3>Don't use <code>dl</code> for dialogue</h3>
    <p><code>dl</code> element is restricted to an association list in HTML.</p>
    <p>Bad:</p>
    <pre><code>&lt;dl&gt;
  &lt;dt&gt;Costello&lt;/dt&gt;
  &lt;dd&gt;Look, you gotta first baseman?&lt;/dd&gt;
  &lt;dt&gt;Abbott&lt;/dt&gt;
  &lt;dd&gt;Certainly.&lt;/dd&gt;
  &lt;dt&gt;Costello&lt;/dt&gt;
  &lt;dd&gt;Who's playing first?&lt;/dd&gt;
  &lt;dt&gt;Abbott&lt;/dt&gt;
  &lt;dd&gt;That's right.&lt;/dd&gt;
  &lt;dt&gt;Costello becomes exasperated.&lt;/dd&gt;
  &lt;dt&gt;Costello&lt;/dt&gt;
  &lt;dd&gt;When you pay off the first baseman every month, who gets the money?&lt;/dd&gt;
  &lt;dt&gt;Abbott&lt;/dt&gt;
  &lt;dd&gt;Every dollar of it.&lt;/dd&gt;
&lt;/dl&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;p&gt;Costello: Look, you gotta first baseman?&lt;/p&gt;
&lt;p&gt;Abbott: Certainly.&lt;/p&gt;
&lt;p&gt;Costello: Who's playing first?&lt;/p&gt;
&lt;p&gt;Abbott: That's right.&lt;/p&gt;
&lt;p&gt;Costello becomes exasperated.&lt;/p&gt;
&lt;p&gt;Costello: When you pay off the first baseman every month, who gets the money?&lt;/p&gt;
&lt;p&gt;Abbott: Every dollar of it.&lt;/p&gt;
</code></pre>
    <h3>Place <code>figcaption</code> element as first or last child of <code>figure</code> element</h3>
    <p>Spec disallows <code>figcaption</code> element in the middle of <code>figure</code> element.</p>
    <p>Bad:</p>
    <pre><code>&lt;figure&gt;
  &lt;img alt="Front cover of the “HTML Best Practices” book" src="/img/front-cover.png"&gt;
  &lt;figcaption&gt;“HTML Best Practices” Cover Art&lt;/figcaption&gt;
  &lt;img alt="Back cover of the “HTML Best Practices” book" src="/img/back-cover.png"&gt;
&lt;/figure&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;figure&gt;
  &lt;img alt="Front cover of the “HTML Best Practices” book" src="/img/front-cover.png"&gt;
  &lt;img alt="Back cover of the “HTML Best Practices” book" src="/img/back-cover.png"&gt;
  &lt;figcaption&gt;“HTML Best Practices” Cover Art&lt;/figcaption&gt;
&lt;/figure&gt;
</code></pre>
    <h3>Use <code>main</code> element</h3>
    <p><code>main</code> element can be used wrapping contents.</p>
    <p>Bad:</p>
    <pre><code>&lt;div id="content"&gt;
  ...
&lt;/div&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;main&gt;
  ...
&lt;/main&gt;
</code></pre>
    <h3>Avoid <code>div</code> element as much as possible</h3>
    <p><code>div</code> element is an element of last resort.</p>
    <p>Bad:</p>
    <pre><code>&lt;div class="chapter"&gt;
  ...
&lt;/div&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;section&gt;
  ...
&lt;/section&gt;
</code></pre>
    <h2 id="textlevelsemantics">Text-level semantics</h2>
    <h3>Don't split same link that can be grouped</h3>
    <p><code>a</code> element can wrap almost all elements (except interactive elements like form
      controls and <code>a</code> element itself).</p>
    <p>Bad:</p>
    <pre><code>&lt;h1&gt;&lt;a href="https://whatwg.org/"&gt;WHATWG&lt;/a&gt;&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://whatwg.org/"&gt;A community maintaining and evolving HTML since 2004.&lt;/a&gt;&lt;/p&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;a href="https://whatwg.org/"&gt;
  &lt;h1&gt;WHATWG&lt;/h1&gt;

  &lt;p&gt;A community maintaining and evolving HTML since 2004.&lt;/p&gt;
&lt;/a&gt;
</code></pre>
    <h3>Use <code>download</code> attribute for downloading a resource</h3>
    <p>It will force browsers to download linked resource to the storage.</p>
    <p>Bad:</p>
    <pre><code>&lt;a href="/downloads/offline.zip"&gt;offline version&lt;/a&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;a download href="/downloads/offline.zip"&gt;offline version&lt;/a&gt;
</code></pre>
    <h3>Use <code>rel</code>, <code>hreflang</code>, and <code>type</code> attribute if needed</h3>
    <p>These hints help applications to handle linked resources.</p>
    <p>Bad:</p>
    <pre><code>&lt;a href="/ja/pdf"&gt;Japanese PDF version&lt;/a&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;a href="/ja/pdf" hreflang="ja" rel="alternate" type="application/pdf"&gt;Japanese PDF version&lt;/a&gt;
</code></pre>
    <h3>Clear link text</h3>
    <p>Link text should be the label of its linked resource.</p>
    <p>Bad:</p>
    <pre><code>&lt;p&gt;&lt;a href="/pdf" rel="alternate" type="application/pdf"&gt;Click here&lt;/a&gt; to view PDF version.&lt;/p&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;p&gt;&lt;a href="/pdf" rel="alternate" type="application/pdf"&gt;PDF version&lt;/a&gt; is also available.&lt;/p&gt;
</code></pre>
    <h3>Don't use <code>em</code> element for warning or caution</h3>
    <p>These are seriousness. So, <code>strong</code> element is more appropriate.</p>
    <p>Bad:</p>
    <pre><code>&lt;em&gt;Caution!&lt;/em&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;strong&gt;Caution!&lt;/strong&gt;
</code></pre>
    <h3>Avoid <code>s</code>, <code>i</code>, <code>b</code>, and <code>u</code> element as much as possible</h3>
    <p>These elements' semantics is too difficult to humans.</p>
    <p>Bad:</p>
    <pre><code>&lt;i class="icon-search"&gt;&lt;/i&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;span class="icon-search" aria-hidden="true"&gt;&lt;/span&gt;
</code></pre>
    <h3>Don't put quotes to <code>q</code> element</h3>
    <p>Quotes are provided by the browser.</p>
    <p>Bad:</p>
    <pre><code>&lt;q&gt;“For writing maintainable and scalable HTML documents”&lt;/q&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;q&gt;For writing maintainable and scalable HTML documents&lt;/q&gt;
</code></pre>
    <p>Also good:</p>
    <pre><code>“For writing maintainable and scalable HTML documents”
</code></pre>
    <h3>Add <code>title</code> attribute to <code>abbr</code> element</h3>
    <p>There is no other way to represent its expansion.</p>
    <p>Bad:</p>
    <pre><code>&lt;abbr&gt;HBP&lt;/abbr&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;abbr title="HTML Best Practices"&gt;HBP&lt;/abbr&gt;
</code></pre>
    <h3>Markup <code>ruby</code> element verbosely</h3>
    <p><code>ruby</code> element support is not completed across the modern browsers.</p>
    <p>Bad:</p>
    <pre><code>&lt;ruby&gt;HTML&lt;rt&gt;えいちてぃーえむえる&lt;/ruby&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;ruby&gt;HTML&lt;rp&gt; (&lt;/rp&gt;&lt;rt&gt;えいちてぃーえむえる&lt;/rt&gt;&lt;rp&gt;) &lt;/rp&gt;&lt;/ruby&gt;
</code></pre>
    <h3>Add <code>datetime</code> attribute to non-machine-readable <code>time</code> element</h3>
    <p>When <code>datetime</code> attribute does not present, the format of <code>time</code> element's
      content is restricted.</p>
    <p>Bad:</p>
    <pre><code>&lt;time&gt;Dec 19, 2014&lt;/time&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;time datetime="2014-12-19"&gt;Dec 19, 2014&lt;/time&gt;
</code></pre>
    <h3>Specify code language with <code>class</code> attribute prefixed with <code>language-</code></h3>
    <p>This is not a formal way, but spec mentions this.</p>
    <p>Bad:</p>
    <pre><code><code>&amp;lt;!DOCTYPE html&amp;gt;</code>
</code></pre>
    <p>Good:</p>
    <pre><code><code class="language-html">&amp;lt;!DOCTYPE html&amp;gt;</code>
</code></pre>
    <h3>Keep <code>kbd</code> element as simple as possible</h3>
    <p>Nesting <code>kbd</code> element is too difficult to humans.</p>
    <p>Bad:</p>
    <pre><code>&lt;kbd&gt;&lt;kbd&gt;Ctrl&lt;/kbd&gt;+&lt;kbd&gt;F5&lt;/kbd&gt;&lt;/kbd&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;kbd&gt;Ctrl+F5&lt;/kbd&gt;
</code></pre>
    <h3>Avoid <code>span</code> element as much as possible</h3>
    <p><code>span</code> element is an element of last resort.</p>
    <p>Bad:</p>
    <pre><code>HTML &lt;span class="best"&gt;Best&lt;/span&gt; Practices
</code></pre>
    <p>Good:</p>
    <pre><code>HTML &lt;em&gt;Best&lt;/em&gt; Practices
</code></pre>
    <h3>Break after <code>br</code> element</h3>
    <p>Line break should be needed where <code>br</code> element is used.</p>
    <p>Bad:</p>
    <pre><code>&lt;p&gt;HTML&lt;br&gt;Best&lt;br&gt;Practices&lt;/p&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;p&gt;HTML&lt;br&gt;
Best&lt;br&gt;
Practices&lt;/p&gt;
</code></pre>
    <h3>Don't use <code>br</code> element only for presentational purpose</h3>
    <p><code>br</code> element is not for line breaking, it is for line breaks in the contents.</p>
    <p>Bad:</p>
    <pre><code>&lt;p&gt;&lt;label&gt;Rule name: &lt;input name="rule-name" type="text"&gt;&lt;/label&gt;&lt;br&gt;
&lt;label&gt;Rule description:&lt;br&gt;
&lt;textarea name="rule-description"&gt;&lt;/textarea&gt;&lt;/label&gt;&lt;/p&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;p&gt;&lt;label&gt;Rule name: &lt;input name="rule-name" type="text"&gt;&lt;/label&gt;&lt;/p&gt;
&lt;p&gt;&lt;label&gt;Rule description:&lt;br&gt;
&lt;textarea name="rule-description"&gt;&lt;/textarea&gt;&lt;/label&gt;&lt;/p&gt;
</code></pre>
    <h2 id="edits">Edits</h2>
    <h3>Don't stride <code>ins</code> and <code>del</code> element over other elements</h3>
    <p>Elements cannot overflow other elements.</p>
    <p>Bad:</p>
    <pre><code>&lt;p&gt;For writing maintainable and scalable HTML documents.&lt;del&gt; And for mental stability.&lt;/p&gt;

&lt;p&gt;Don't trust!&lt;/p&gt;&lt;/del&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;p&gt;For writing maintainable and scalable HTML documents.&lt;del&gt; And for mental stability.&lt;/del&gt;&lt;/p&gt;

&lt;del&gt;&lt;p&gt;Don't trust!&lt;/p&gt;&lt;/del&gt;
</code></pre>
    <h2 id="embeddedcontent">Embedded content</h2>
    <h3>Provide fallback <code>img</code> element for <code>picture</code> element</h3>
    <p>The support of <code>picture</code> element is not good yet.</p>
    <p>Bad:</p>
    <pre><code>&lt;picture&gt;
  &lt;source srcset="/img/logo.webp" type="image/webp"&gt;
  &lt;source srcset="/img/logo.hdp" type="image/vnd.ms-photo"&gt;
  &lt;source srcset="/img/logo.jp2" type="image/jp2"&gt;
  &lt;source srcset="/img/logo.jpg" type="image/jpg"&gt;
&lt;/picture&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;picture&gt;
  &lt;source srcset="/img/logo.webp" type="image/webp"&gt;
  &lt;source srcset="/img/logo.hdp" type="image/vnd.ms-photo"&gt;
  &lt;source srcset="/img/logo.jp2" type="image/jp2"&gt;
  &lt;img src="/img/logo.jpg"&gt;
&lt;/picture&gt;
</code></pre>
    <h3>Add <code>alt</code> attrbute to <code>img</code> element if needed</h3>
    <p><code>alt</code> attribute helps those who cannot process images or have image loading
      disabled.</p>
    <p>Bad:</p>
    <pre><code>&lt;img src="/img/logo.png"&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;img alt="HTML Best Practices" src="/img/logo.png"&gt;
</code></pre>
    <h3>Empty <code>alt</code> attribute if possible</h3>
    <p>If the image is supplemental, there is equivalent content somewhere in the near.</p>
    <p>Bad:</p>
    <pre><code>&lt;img alt="Question mark icon" src="/img/icon/help.png"&gt; Help
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;img alt="" src="/img/icon/help.png"&gt; Help
</code></pre>
    <h3>Omit <code>alt</code> attribute if possible</h3>
    <p>Sometimes you don't know what text is suitable for <code>alt</code> attribute.</p>
    <p>Bad:</p>
    <pre><code>&lt;img alt="CAPTCHA" src="captcha.cgi?id=82174"&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;img src="captcha.cgi?id=82174" title="CAPTCHA"&gt;
(If you cannot see the image, you can use an &lt;a href="?audio"&gt;audio&lt;/a&gt; test instead.)
</code></pre>
    <h3>Empty <code>iframe</code> element</h3>
    <p>There is some restriction in its content. Being empty is always safe.</p>
    <p>Bad:</p>
    <pre><code>&lt;iframe src="/ads/default.html"&gt;
  &lt;p&gt;If your browser support inline frame, ads are displayed here.&lt;/p&gt;
&lt;/iframe&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;iframe src="/ads/default.html"&gt;&lt;/iframe&gt;
</code></pre>
    <h3>Markup <code>map</code> element content</h3>
    <p>This content presents to a screen reader.</p>
    <p>Bad:</p>
    <pre><code>&lt;map name="toc"&gt;
  &lt;a href="#general"&gt;General&lt;/a&gt;
  &lt;area alt="General" coords="0, 0, 40, 40" href="#General"&gt; |
  &lt;a href="#the_root_element"&gt;The root element&lt;/a&gt;
  &lt;area alt="The root element" coords="50, 0, 90, 40" href="#the_root_element"&gt; |
  &lt;a href="#sections"&gt;Sections&lt;/a&gt;
  &lt;area alt="Sections" coords="100, 0, 140, 40" href="#sections"&gt;
&lt;/map&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;map name="toc"&gt;
  &lt;p&gt;
    &lt;a href="#general"&gt;General&lt;/a&gt;
    &lt;area alt="General" coords="0, 0, 40, 40" href="#General"&gt; |
    &lt;a href="#the_root_element"&gt;The root element&lt;/a&gt;
    &lt;area alt="The root element" coords="50, 0, 90, 40" href="#the_root_element"&gt; |
    &lt;a href="#sections"&gt;Sections&lt;/a&gt;
    &lt;area alt="Sections" coords="100, 0, 140, 40" href="#sections"&gt;
  &lt;/p&gt;
&lt;/map&gt;
</code></pre>
    <h3>Provide fallback content for <code>audio</code> or <code>video</code> element</h3>
    <p>Fallback content is needed for newly introduced elements in HTML.</p>
    <p>Bad:</p>
    <pre><code>&lt;video&gt;
  &lt;source src="/mov/theme.mp4" type="video/mp4"&gt;
  &lt;source src="/mov/theme.ogv" type="video/ogg"&gt;
  ...
&lt;/video&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;video&gt;
  &lt;source src="/mov/theme.mp4" type="video/mp4"&gt;
  &lt;source src="/mov/theme.ogv" type="video/ogg"&gt;
  ...
  &lt;iframe src="//www.youtube.com/embed/..." allowfullscreen&gt;&lt;/iframe&gt;
&lt;/video&gt;
</code></pre>
    <h2 id="tabulardata">Tabular data</h2>
    <h3>Write one cell per line</h3>
    <p>Long lines are hard to scan.</p>
    <p>Bad:</p>
    <pre><code>&lt;tr&gt;
  &lt;td&gt;General&lt;/td&gt;&lt;td&gt;The root Element&lt;/td&gt;&lt;td&gt;Sections&lt;/td&gt;
&lt;/tr&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;tr&gt;
  &lt;td&gt;General&lt;/td&gt;
  &lt;td&gt;The root Element&lt;/td&gt;
  &lt;td&gt;Sections&lt;/td&gt;
&lt;/tr&gt;
</code></pre>
    <h3>Use <code>th</code> element for header cell</h3>
    <p>There is no reason to avoid this.</p>
    <p>Bad:</p>
    <pre><code>&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Element&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;Empty&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;&lt;strong&gt;Tag omission&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;<code>pre</code>&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;No&lt;/td&gt;
      &lt;td&gt;Neither tag is omissible&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;<code>img</code>&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;Yes&lt;/td&gt;
      &lt;td&gt;No end tag&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Element&lt;/th&gt;
      &lt;th&gt;Empty&lt;/th&gt;
      &lt;th&gt;Tag omission&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;th&gt;<code>pre</code>&lt;/th&gt;
      &lt;td&gt;No&lt;/td&gt;
      &lt;td&gt;Neither tag is omissible&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;th&gt;<code>img</code>&lt;/th&gt;
      &lt;td&gt;Yes&lt;/td&gt;
      &lt;td&gt;No end tag&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
</code></pre>
    <h2 id="forms">Forms</h2>
    <h3>Wrap form control with <code>label</code> element</h3>
    <p><code>label</code> element helps focusing form element.</p>
    <p>Bad:</p>
    <pre><code>&lt;p&gt;Query: &lt;input name="q" type="text"&gt;&lt;/p&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;p&gt;&lt;label&gt;Query: &lt;input name="q" type="text"&gt;&lt;/label&gt;&lt;/p&gt;
</code></pre>
    <h3>Omit <code>for</code> attribute if possible</h3>
    <p><code>label</code> element can contain some form elements.</p>
    <p>Bad:</p>
    <pre><code>&lt;label for="q"&gt;Query: &lt;/label&gt;&lt;input id="q" name="q" type="text"&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;label&gt;Query: &lt;input name="q" type="text"&gt;&lt;/label&gt;
</code></pre>
    <h3>Use appropriate <code>type</code> attribute for <code>input</code> element</h3>
    <p>With appropriate <code>type</code>, a browser gives tiny features to the <code>input</code> element.</p>
    <p>Bad:</p>
    <pre><code>&lt;label&gt;Search keyword: &lt;input name="q" type="text"&gt;&lt;/label&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;label&gt;Search keyword: &lt;input name="q" type="search"&gt;&lt;/label&gt;
</code></pre>
    <h3>Add <code>value</code> attribute to <code>input type="submit"</code></h3>
    <p>The default label for submit button is not standarized across the browser and
      languages.</p>
    <p>Bad:</p>
    <pre><code>&lt;input type="submit"&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;input type="submit" value="Search"&gt;
</code></pre>
    <h3>Add <code>title</code> attribute to <code>input</code> element when there is <code>pattern</code> attribute</h3>
    <p>If input text does not match to <code>pattern</code> attribute, the value of <code>title</code>
      attribute will be display as a hint.</p>
    <p>Bad:</p>
    <pre><code>&lt;input name="security-code" pattern="[0-9]{3}" type="text"&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;input name="security-code" pattern="[0-9]{3}" title="A security code is a number in three figures." type="text"&gt;
</code></pre>
    <h3>Don't use <code>placeholder</code> attribute for labeling</h3>
    <p><code>label</code> element is for a label, <code>placeholder</code> attribute is for a short hint.</p>
    <p>Bad:</p>
    <pre><code>&lt;input name="email" placeholder="Email" type="text"&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;label&gt;Email: &lt;input name="email" placeholder="john.doe@example.com" type="text"&gt;&lt;/label&gt;
</code></pre>
    <h3>Write one <code>option</code> element per line</h3>
    <p>Long lines are hard to scan.</p>
    <p>Bad:</p>
    <pre><code>&lt;datalist id="toc"&gt;
  &lt;option label="General"&gt;&lt;option label="The root element"&gt;&lt;option label="Sections"&gt;
&lt;/datalist&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;datalist id="toc"&gt;
  &lt;option label="General"&gt;
  &lt;option label="The root element"&gt;
  &lt;option label="Sections"&gt;
&lt;/datalist&gt;
</code></pre>
    <h3>Add <code>max</code> attribute to <code>progress</code> element</h3>
    <p>With <code>max</code> attribute, the <code>value</code> attribute can be written in an easy format.</p>
    <p>Bad:</p>
    <pre><code>&lt;progress value="0.5"&gt; 50%&lt;/progress&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;progress max="100" value="50"&gt; 50%&lt;/progress&gt;
</code></pre>
    <h3>Add <code>min</code> and <code>max</code> attribute to <code>meter</code> element</h3>
    <p>With <code>min</code> and <code>max</code> attribute, the <code>value</code> attribute can be written in an easy
      format.</p>
    <p>Bad:</p>
    <pre><code>&lt;meter value="0.5"&gt; 512GB used (1024GB total)&lt;/meter&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;meter min="0" max="1024" value="512"&gt; 512GB used (1024GB total)&lt;/meter&gt;
</code></pre>
    <h3>Place <code>legend</code> element as the first child of <code>fieldset</code> element</h3>
    <p>Spec requires this.</p>
    <p>Bad:</p>
    <pre><code>&lt;fieldset&gt;
  &lt;p&gt;&lt;label&gt;Is this section useful?: &lt;input name="usefulness-general" type="checkbox"&gt;&lt;/label&gt;&lt;/p&gt;
  ...
  &lt;legend&gt;About "General"&lt;/legend&gt;
&lt;/fieldset&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;fieldset&gt;
  &lt;legend&gt;About "General"&lt;/legend&gt;
  &lt;p&gt;&lt;label&gt;Is this section useful?: &lt;input name="usefulness-general" type="checkbox"&gt;&lt;/label&gt;&lt;/p&gt;
  ...
&lt;/fieldset&gt;
</code></pre>
    <h2 id="scripting">Scripting</h2>
    <h3>Omit <code>type</code> attribute for JavaScript</h3>
    <p>In HTML, the default <code>type</code> attribute's value of <code>script</code> element is
      <code>text/javascript</code>.
    </p>
    <p>Bad:</p>
    <pre><code>&lt;script type="text/javascript"&gt;
  ...
&lt;/script&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;script&gt;
  ...
&lt;/script&gt;
</code></pre>
    <h3>Don't comment out contents of <code>script</code> element</h3>
    <p>This ritual is for the old browser.</p>
    <p>Bad:</p>
    <pre><code>&lt;script&gt;
/*&lt;![CDATA[*/
  ...
/*]]&gt;*/
&lt;/script&gt;
</code></pre>
    <p>Also bad:</p>
    <pre><code>&lt;script&gt;
&lt;!--
  ...
// --&gt;
&lt;/script&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;script&gt;
  ...
&lt;/script&gt;
</code></pre>
    <h3>Don't use script-injected <code>script</code> element</h3>
    <p><code>async</code> attribute is the best for both simplicity and performance.</p>
    <p>Bad:</p>
    <pre><code>&lt;script&gt;
  var script = document.createElement("script");
  script.async = true;
  script.src = "//example.com/widget.js";
  document.getElementsByTagName("head")[0].appendChild(script);
&lt;/script&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;script async defer src="https://example.com/widget.js"&gt;&lt;/script&gt;
</code></pre>
    <h2 id="other">Other</h2>
    <h3>Indent consistently</h3>
    <p>Indentation is important for readability.</p>
    <p>Bad:</p>
    <pre><code>&lt;html&gt;
    &lt;head&gt;
      ...
    &lt;/head&gt;
  &lt;body&gt;
    ...
  &lt;/body&gt;
&lt;/html&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;html&gt;
  &lt;head&gt;
    ...
  &lt;/head&gt;
  &lt;body&gt;
    ...
  &lt;/body&gt;
&lt;/html&gt;
</code></pre>
    <h3>Use absolute path for internal links</h3>
    <p>An absolute path works better on your localhost without internet connection.</p>
    <p>Bad:</p>
    <pre><code>&lt;link rel="apple-touch-icon" href="http://you.example.com/apple-touch-icon-precomposed.png"&gt;
...
&lt;p&gt;You can find more at &lt;a href="//you.example.com/contact.html"&gt;contact page&lt;/a&gt;.&lt;/p&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;link rel="apple-touch-icon" href="/apple-touch-icon-precomposed.png"&gt;
...
&lt;p&gt;You can find more at &lt;a href="/contact.html"&gt;contact page&lt;/a&gt;.&lt;/p&gt;
</code></pre>
    <h3>Don't use protocol-relative URL for external resources</h3>
    <p>With protocol, you can load external resources reliably and safely.</p>
    <p>Bad:</p>
    <pre><code>&lt;script src="//example.com/js/library.js"&gt;
</code></pre>
    <p>Good:</p>
    <pre><code>&lt;script src="https://example.com/js/library.js"&gt;
</code></pre>
  </div>
  <div>
    <h2 id="contributors">Contributors</h2>
    <ul>
      <li><a href="https://github.com/hail2u">@hail2u_</a></li>
      <li><a href="https://github.com/momdo">@momdo</a></li>
    </ul>
    <h2 id="translators">Translators</h2>
    <ul>
      <li><a href="https://github.com/costinlotreanu">@costinlotreanu</a></li>
      <li><a href="https://github.com/edgar-avila">@edgar-avila</a></li>
      <li><a href="https://github.com/kobyborali">@kobyborali</a></li>
      <li><a href="https://github.com/m1nhnv">@m1nhnv</a></li>
      <li><a href="https://github.com/mrcaidev">@mrcaidev</a></li>
      <li><a href="https://github.com/naufalk25">@naufalk25</a></li>
      <li><a href="https://github.com/oebelus">@oebelus</a></li>
      <li><a href="https://github.com/sahilmaniyar">@sahilmaniyar</a></li>
      <li><a href="https://github.com/shayanthenerd">@shayanthenerd</a></li>
      <li><a href="https://github.com/sliderkh">@sliderkh</a></li>
      <li><a href="https://github.com/stenbaek">@stenbaek</a></li>
      <li><a href="https://github.com/techhtml">@techhtml</a></li>
      <li><a href="https://github.com/umutphp">@umutphp</a></li>
      <li><a href="https://github.com/victorchao996">@victorchao996</a></li>
      <li><a href="https://github.com/wesleynepo">@wesleynepo</a></li>
      <li><a href="https://github.com/zulkar29">@zulkar29</a></li>
    </ul>
    <h2 id="license">License</h2>
    <p><a href="http://creativecommons.org/publicdomain/zero/1.0/">CC0</a></p>
  </div>
</blockquote>
html {
  scroll-behavior: smooth;
}
body {
  margin-block: 2rem;
  margin-inline: max(2rem, 50% - 24rem);
}
hr {
  border: none;
  border-block-start: solid 1px;
  color: inherit;
  margin-block: 2rem;
  margin-inline: 40%;
}
blockquote {
  display: contents;
}
details._toc {
  & {
    border: solid 1px color-mix(in srgb, transparent, currentcolor 20%);
    border-radius: 4px;
    padding: 1rem;
    position: relative;
  }
  & > * {
    isolation: isolate;
  }
  & > summary {
    & {
      cursor: pointer;
    }
    &::before {
      content: "";
      position: absolute;
      inset: 0;
    }
  }

  /* Elements generated by JavaScript */
  & > ol {
    & {
      counter-reset: toc-h2 toc-h3 toc-h4 toc-h5 toc-h6;
      display: grid;
      grid: auto-flow / repeat(5, auto) 1fr;
      padding: 0;
    }
    & > li {
      & {
        display: grid;
        grid: auto-flow / subgrid;
        grid-column: 1 / -1;
        margin: 0;
      }
      &::before {
        text-align: end;
        white-space: pre;
      }
      & > a:not(:hover, :focus-visible) {
        text-decoration: none;
      }
      &.h2 {
        & {
          counter-increment: toc-h2;
          counter-reset: toc-h3;
        }
        &::before {
          content: counter(toc-h2) ". ";
          grid-column: 1 / span 1;
        }
        & > a {
          grid-column: 2 / span 5;
        }
      }
      &.h3 {
        & {
          counter-increment: toc-h3;
          counter-reset: toc-h4;
        }
        &::before {
          content: counter(toc-h3) ". ";
          grid-column: 2 / span 1;
        }
        & > a {
          grid-column: 3 / span 4;
        }
      }
      &.h4 {
        & {
          counter-increment: toc-h4;
          counter-reset: toc-h5;
        }
        &::before {
          content: counter(toc-h4) ". ";
          grid-column: 3 / span 1;
        }
        & > a {
          grid-column: 4 / span 3;
        }
      }
      &.h5 {
        & {
          counter-increment: toc-h5;
          counter-reset: toc-h6;
        }
        &::before {
          content: counter(toc-h5) ". ";
          grid-column: 4 / span 1;
        }
        & > a {
          grid-column: 5 / span 2;
        }
      }
      &.h6 {
        & {
          counter-increment: toc-h6;
        }
        &::before {
          content: counter(toc-h6) ". ";
          grid-column: 5 / span 1;
        }
        & > a {
          grid-column: 6 / span 1;
        }
      }
    }
  }
  /* / Elements generated by JavaScript */
}
((d) => {
  const tocAll = d.querySelectorAll("details._toc[hidden]");

  for (const toc of tocAll) {
    const tocTargetAll = toc.parentNode.querySelectorAll(
      "._toc~:is(h2,h3,h4,h5,h6),._toc~* :is(h2,h3,h4,h5,h6)"
    );

    if (!tocTargetAll.length) {
      continue;
    }

    const tocList = d.createElement("ol");

    for (const [index, tocTarget] of tocTargetAll.entries()) {
      let tocTargetId;

      if (tocTarget.id) {
        tocTargetId = tocTarget.id;
      } else {
        tocTargetId =
          `_${index + 1}_` + encodeURIComponent(tocTarget.textContent);
        tocTarget.id = tocTargetId;
      }

      const tocItem = document.createElement("li");
      tocItem.classList.add(tocTarget.tagName.toLowerCase());
      tocItem.innerHTML = `<a href="#${tocTargetId}">${tocTarget.textContent}</a>`;

      tocList.appendChild(tocItem);
    }

    toc.appendChild(tocList);
    toc.hidden = false;
  }
})(document);

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.