Skip to content

Commit dc39c82

Browse files
committed
Update HTML/CSS style guide
* Add an optional line-wrapping recommendation. * Update links to the WHATWG HTML spec which were redirecting. * Minor content and markup edits.
1 parent 191c247 commit dc39c82

File tree

1 file changed

+38
-59
lines changed

1 file changed

+38
-59
lines changed

htmlcssguide.html

+38-59
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,12 @@
1313
<h1>Google HTML/CSS Style Guide</h1>
1414
<h2 id="Background">1 Background</h2>
1515

16-
<p></p>
17-
1816
<p>This document defines formatting and style rules for HTML and CSS. It aims at
1917
improving collaboration, code quality, and enabling supporting infrastructure.
2018
It applies to raw, working files that use HTML and CSS, including GSS files.
2119
Tools are free to obfuscate, minify, and compile as long as the general code
2220
quality is maintained.</p>
2321

24-
<p></p>
25-
26-
<p></p>
27-
2822
<h2 id="General">2 General</h2>
2923

3024
<h3 id="General_Style_Rules">2.1 General Style Rules</h3>
@@ -59,14 +53,6 @@ <h4 id="Protocol">2.1.1 Protocol</h4>
5953
@import 'https://fonts.googleapis.com/css?family=Open+Sans';
6054
</code></pre>
6155

62-
63-
64-
<p></p>
65-
66-
<p></p>
67-
68-
<p></p>
69-
7056
<h3 id="General_Formatting_Rules">2.2 General Formatting Rules</h3>
7157

7258
<h4 id="Indentation">2.2.1 Indentation</h4>
@@ -167,8 +153,6 @@ <h4 id="Action_Items">2.3.3 Action Items</h4>
167153
&lt;center&gt;Test&lt;/center&gt;
168154
</code></pre>
169155

170-
<p></p>
171-
172156
<pre><code class="language-html prettyprint">&lt;!-- TODO: remove optional tags --&gt;
173157
&lt;ul&gt;
174158
&lt;li&gt;Apples&lt;/li&gt;
@@ -233,8 +217,6 @@ <h4 id="Semantics">3.1.3 Semantics</h4>
233217
<p>Using HTML according to its purpose is important for accessibility, reuse, and
234218
code efficiency reasons.</p>
235219

236-
<p></p>
237-
238220
<pre><code class="language-html prettyprint badcode">&lt;!-- Not recommended --&gt;
239221
&lt;div onclick="goToRecommendations();"&gt;All recommendations&lt;/div&gt;
240222
</code></pre>
@@ -259,8 +241,6 @@ <h4 id="Multimedia_Fallback">3.1.4 Multimedia Fallback</h4>
259241
whose purpose is purely decorative which you cannot immediately use CSS for, use
260242
no alternative text, as in <code>alt=""</code>.)</p>
261243

262-
<p></p>
263-
264244
<pre><code class="language-html prettyprint badcode">&lt;!-- Not recommended --&gt;
265245
&lt;img src="spreadsheet.png"&gt;
266246
</code></pre>
@@ -288,8 +268,6 @@ <h4 id="Separation_of_Concerns">3.1.5 Separation of Concerns</h4>
288268
maintenance reasons. It is always more expensive to change HTML documents and
289269
templates than it is to update style sheets and scripts.</p>
290270

291-
<p></p>
292-
293271
<pre><code class="language-html prettyprint badcode">&lt;!-- Not recommended --&gt;
294272
&lt;!DOCTYPE html&gt;
295273
&lt;title&gt;HTML sucks&lt;/title&gt;
@@ -338,7 +316,7 @@ <h4 id="Optional_Tags">3.1.7 Optional Tags</h4>
338316
<p>Omit optional tags (optional).</p>
339317

340318
<p>For file size optimization and scannability purposes, consider omitting optional
341-
tags. The <a href="https://whatwg.org/specs/web-apps/current-work/multipage/syntax.html#syntax-tag-omission">HTML5 specification</a>
319+
tags. The <a href="https://html.spec.whatwg.org/multipage/syntax.html#syntax-tag-omission">HTML5 specification</a>
342320
defines what tags can be omitted.</p>
343321

344322
<p>(This approach may require a grace period to be established as a wider guideline
@@ -372,8 +350,8 @@ <h4 id="type_Attributes">3.1.8 <code>type</code> Attributes</h4>
372350
(unless not using JavaScript).</p>
373351

374352
<p>Specifying <code>type</code> attributes in these contexts is not necessary as HTML5 implies
375-
<a href="https://whatwg.org/specs/web-apps/current-work/multipage/semantics.html#attr-style-type"><code>text/css</code></a>
376-
and <a href="https://whatwg.org/specs/web-apps/current-work/multipage/scripting.html#attr-script-type"><code>text/javascript</code></a>
353+
<a href="https://html.spec.whatwg.org/multipage/obsolete.html#attr-style-type"><code>text/css</code></a>
354+
and <a href="https://html.spec.whatwg.org/multipage/scripting.html#attr-script-type"><code>text/javascript</code></a>
377355
as defaults. This can be safely done even for older browsers.</p>
378356

379357
<pre><code class="language-html prettyprint badcode">&lt;!-- Not recommended --&gt;
@@ -435,7 +413,37 @@ <h4 id="General_Formatting">3.2.1 General Formatting</h4>
435413
&lt;/table&gt;
436414
</code></pre>
437415

438-
<h4 id="HTML_Quotation_Marks">3.2.2 HTML Quotation Marks</h4>
416+
<h4 id="HTML_Line-Wrapping">3.2.2 HTML Line-Wrapping</h4>
417+
418+
<p>Break long lines (optional).</p>
419+
420+
<p>While there is no column limit recommendation for HTML, you may consider
421+
wrapping long lines if it significantly improves readability.</p>
422+
423+
<p>When line-wrapping, each continuation line should be indented at least 4
424+
additional spaces from the original line.</p>
425+
426+
<pre><code class="language-html prettyprint">&lt;md-progress-circular md-mode="indeterminate" class="md-accent"
427+
ng-show="ctrl.loading" md-diameter="35"&gt;
428+
&lt;/md-progress-circular&gt;
429+
</code></pre>
430+
431+
<pre><code class="language-html prettyprint">&lt;md-progress-circular
432+
md-mode="indeterminate"
433+
class="md-accent"
434+
ng-show="ctrl.loading"
435+
md-diameter="35"&gt;
436+
&lt;/md-progress-circular&gt;
437+
</code></pre>
438+
439+
<pre><code class="language-html prettyprint">&lt;md-progress-circular md-mode="indeterminate"
440+
class="md-accent"
441+
ng-show="ctrl.loading"
442+
md-diameter="35"&gt;
443+
&lt;/md-progress-circular&gt;
444+
</code></pre>
445+
446+
<h4 id="HTML_Quotation_Marks">3.2.3 HTML Quotation Marks</h4>
439447

440448
<p>When quoting attributes values, use double quotation marks.</p>
441449

@@ -586,7 +594,7 @@ <h4 id="Leading_0s">4.1.7 Leading 0s</h4>
586594

587595
<p>Omit leading &#8220;0&#8221;s in values.</p>
588596

589-
<p>Do not use put <code>0</code>s in front of values or lengths between -1 and 1.</p>
597+
<p>Do not put <code>0</code>s in front of values or lengths between -1 and 1.</p>
590598

591599
<pre><code class="language-css prettyprint">font-size: .8em;
592600
</code></pre>
@@ -614,10 +622,6 @@ <h4 id="Prefixes">4.1.9 Prefixes</h4>
614622
external sites use prefixes (as namespaces) for ID and class names. Use short,
615623
unique identifiers followed by a dash.</p>
616624

617-
<p></p>
618-
619-
<p></p>
620-
621625
<p>Using namespaces helps preventing naming conflicts and can make maintenance
622626
easier, for example in search and replace operations.</p>
623627

@@ -659,10 +663,6 @@ <h4 id="Hacks">4.1.11 Hacks</h4>
659663
means using detection and hacks more frequently&#8212;and more frequently is too
660664
frequently.</p>
661665

662-
<p></p>
663-
664-
<p></p>
665-
666666
<h3 id="CSS_Formatting_Rules">4.2 CSS Formatting Rules</h3>
667667

668668
<h4 id="Declaration_Order">4.2.1 Declaration Order</h4>
@@ -811,11 +811,10 @@ <h4 id="Rule_Separation">4.2.7 Rule Separation</h4>
811811

812812
<h4 id="CSS_Quotation_Marks">4.2.8 CSS Quotation Marks</h4>
813813

814-
<p>Use single quotation marks for attribute selectors and property values.</p>
815-
816814
<p>Use single (<code>''</code>) rather than double (<code>""</code>) quotation marks for attribute
817-
selectors or property values. Do not use quotation marks in URI values
818-
(<code>url()</code>).</p>
815+
selectors and property values.</p>
816+
817+
<p>Do not use quotation marks in URI values (<code>url()</code>).</p>
819818

820819
<p>Exception: If you do need to use the <code>@charset</code> rule, use double quotation
821820
marks&#8212;<a href="https://www.w3.org/TR/CSS21/syndata.html#charset">single quotation marks are not permitted</a>.</p>
@@ -858,26 +857,6 @@ <h4 id="Section_Comments">4.3.1 Section Comments</h4>
858857
.adw-gallery {}
859858
</code></pre>
860859

861-
862-
863-
<p></p>
864-
865-
<p></p>
866-
867-
868-
869-
<p></p>
870-
871-
<p></p>
872-
873-
874-
875-
876-
877-
<p></p>
878-
879-
<p></p>
880-
881860
<h2 id="Parting_Words">Parting Words</h2>
882861

883862
<p><em>Be consistent.</em></p>

0 commit comments

Comments
 (0)