readability-cli 0.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
guides/htmlcssguide.md ADDED
@@ -0,0 +1,1022 @@
1
+ Google HTML/CSS Style Guide
2
+
3
+
4
+
5
+ # Google HTML/CSS Style Guide
6
+
7
+ ## Background
8
+
9
+ This document defines formatting and style rules for HTML and CSS. It aims at
10
+ improving collaboration, code quality, and enabling supporting infrastructure.
11
+ It applies to raw, working files that use HTML and CSS, including Sass and GSS
12
+ files. Tools are free to obfuscate, minify, and compile as long as the general
13
+ code quality is maintained.
14
+
15
+ ## General
16
+
17
+ ### General Style Rules
18
+
19
+ #### Protocol
20
+
21
+ Use HTTPS for embedded resources where possible.
22
+
23
+ Always use HTTPS (`https:`) for images and other media files, style sheets, and
24
+ scripts, unless the respective files are not available over HTTPS.
25
+
26
+ ```
27
+ <!-- Not recommended: omits the protocol -->
28
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
29
+
30
+ <!-- Not recommended: uses HTTP -->
31
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
32
+ ```
33
+
34
+ ```
35
+ <!-- Recommended -->
36
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
37
+ ```
38
+
39
+ ```
40
+ /* Not recommended: omits the protocol */
41
+ @import '//fonts.googleapis.com/css?family=Open+Sans';
42
+
43
+ /* Not recommended: uses HTTP */
44
+ @import 'http://fonts.googleapis.com/css?family=Open+Sans';
45
+ ```
46
+
47
+ ```
48
+ /* Recommended */
49
+ @import 'https://fonts.googleapis.com/css?family=Open+Sans';
50
+ ```
51
+
52
+ ### General Formatting Rules
53
+
54
+ #### Indentation
55
+
56
+ Indent by 2 spaces at a time.
57
+
58
+ Don’t use tabs or mix tabs and spaces for indentation.
59
+
60
+ ```
61
+ <ul>
62
+ <li>Fantastic
63
+ <li>Great
64
+ </ul>
65
+ ```
66
+
67
+ ```
68
+ .example {
69
+ color: blue;
70
+ }
71
+ ```
72
+
73
+ #### Capitalization
74
+
75
+ Use only lowercase.
76
+
77
+ All code has to be lowercase: This applies to HTML element names, attributes,
78
+ attribute values (unless `text/CDATA`), CSS selectors, properties, and property
79
+ values (with the exception of strings).
80
+
81
+ ```
82
+ <!-- Not recommended -->
83
+ <A HREF="/">Home</A>
84
+ ```
85
+
86
+ ```
87
+ <!-- Recommended -->
88
+ <img src="google.png" alt="Google">
89
+ ```
90
+
91
+ ```
92
+ /* Not recommended */
93
+ color: #E5E5E5;
94
+ ```
95
+
96
+ ```
97
+ /* Recommended */
98
+ color: #e5e5e5;
99
+ ```
100
+
101
+ #### Trailing Whitespace
102
+
103
+ Remove trailing white spaces.
104
+
105
+ Trailing white spaces are unnecessary and can complicate diffs.
106
+
107
+ ```
108
+ <!-- Not recommended -->
109
+ <p>What?_
110
+ ```
111
+
112
+ ```
113
+ <!-- Recommended -->
114
+ <p>Yes please.
115
+ ```
116
+
117
+ ### General Meta Rules
118
+
119
+ #### Encoding
120
+
121
+ Use UTF-8 (no BOM).
122
+
123
+ Make sure your editor uses UTF-8 as character encoding, without a byte order
124
+ mark.
125
+
126
+ Specify the encoding in HTML templates and documents via `<meta
127
+ charset="utf-8">`. Do not specify the encoding of style sheets as these assume
128
+ UTF-8.
129
+
130
+ (More on encodings and when and how to specify them can be found in
131
+ [Handling character encodings in HTML and CSS](https://www.w3.org/International/tutorials/tutorial-char-enc/).)
132
+
133
+ #### Comments
134
+
135
+ Explain code as needed, where possible.
136
+
137
+ Use comments to explain code: What does it cover, what purpose does it serve,
138
+ why is respective solution used or preferred?
139
+
140
+ (This item is optional as it is not deemed a realistic expectation to always
141
+ demand fully documented code. Mileage may vary heavily for HTML and CSS code and
142
+ depends on the project’s complexity.)
143
+
144
+ #### Action Items
145
+
146
+ Mark todos and action items with `TODO`.
147
+
148
+ Highlight todos by using the keyword `TODO` only, not other common formats like
149
+ `@@`.
150
+
151
+ Append action items after a colon as in `TODO: action
152
+ item`.
153
+
154
+ ```
155
+ {# TODO: Revisit centering. #}
156
+ <center>Test</center>
157
+ ```
158
+
159
+ ```
160
+ <!-- TODO: Remove optional tags. -->
161
+ <ul>
162
+ <li>Apples</li>
163
+ <li>Oranges</li>
164
+ </ul>
165
+ ```
166
+
167
+ ## HTML
168
+
169
+ ### HTML Style Rules
170
+
171
+ #### Document Type
172
+
173
+ Use `<!doctype html>`.
174
+
175
+ Always put your HTML in
176
+ [no-quirks mode](https://developer.mozilla.org/en-US/docs/Web/HTML/Quirks_Mode_and_Standards_Mode)
177
+ by including `<!doctype html>` at the beginning of the document.
178
+
179
+ A document without a doctype is rendered in “quirks mode”, and one with a
180
+ different doctype may be rendered in “limited-quirks mode”. These modes don’t
181
+ follow the widely-understood, widely-documented behavior for various core HTML
182
+ and CSS constructs, and are likely to cause subtle failures and
183
+ incompatibilities especially when re-using code that expects no-quirks mode.
184
+
185
+ #### HTML Validity
186
+
187
+ Use valid HTML where possible.
188
+
189
+ Use valid HTML code unless that is not possible due to otherwise unattainable
190
+ performance goals regarding file size.
191
+
192
+ Use tools such as the
193
+ [W3C HTML validator](https://validator.w3.org/nu/)
194
+ to test.
195
+
196
+ Using valid HTML is a measurable baseline quality attribute that contributes to
197
+ learning about technical requirements and constraints, and that ensures proper
198
+ HTML usage.
199
+
200
+ ```
201
+ <!-- Not recommended -->
202
+ <title>Test</title>
203
+ <article>This is only a test.
204
+ ```
205
+
206
+ ```
207
+ <!-- Recommended -->
208
+ <!doctype html>
209
+ <meta charset="utf-8">
210
+ <title>Test</title>
211
+ <article>This is only a test.</article>
212
+ ```
213
+
214
+ #### Semantics
215
+
216
+ Use HTML according to its purpose.
217
+
218
+ Use elements (sometimes incorrectly called “tags”) for what they have been
219
+ created for. For example, use heading elements for headings, `p` elements for
220
+ paragraphs, `a` elements for anchors, etc.
221
+
222
+ Using HTML according to its purpose is important for accessibility, reuse, and
223
+ code efficiency reasons.
224
+
225
+ ```
226
+ <!-- Not recommended -->
227
+ <div onclick="goToRecommendations();">All recommendations</div>
228
+ ```
229
+
230
+ ```
231
+ <!-- Recommended -->
232
+ <a href="recommendations/">All recommendations</a>
233
+ ```
234
+
235
+ #### Multimedia Fallback
236
+
237
+ Provide alternative contents for multimedia.
238
+
239
+ For multimedia, such as images, videos, animated objects via `canvas`, make sure
240
+ to offer alternative access. For images that means use of meaningful alternative
241
+ text (`alt`) and for video and audio transcripts and captions, if available.
242
+
243
+ Providing alternative contents is important for accessibility reasons: A blind
244
+ user has few cues to tell what an image is about without `@alt`, and other users
245
+ may have no way of understanding what video or audio contents are about either.
246
+
247
+ (For images whose `alt` attributes would introduce redundancy, and for images
248
+ whose purpose is purely decorative which you cannot immediately use CSS for, use
249
+ no alternative text, as in `alt=""`.)
250
+
251
+ ```
252
+ <!-- Not recommended -->
253
+ <img src="spreadsheet.png">
254
+ ```
255
+
256
+ ```
257
+ <!-- Recommended -->
258
+ <img src="spreadsheet.png" alt="Spreadsheet screenshot.">
259
+ ```
260
+
261
+ #### Separation of Concerns
262
+
263
+ Separate structure from presentation from behavior.
264
+
265
+ Strictly keep structure (markup), presentation (styling), and behavior
266
+ (scripting) apart, and try to keep the interaction between the three to an
267
+ absolute minimum.
268
+
269
+ That is, make sure documents and templates contain only HTML and HTML that is
270
+ solely serving structural purposes. Move everything presentational into style
271
+ sheets, and everything behavioral into scripts.
272
+
273
+ In addition, keep the contact area as small as possible by linking as few style
274
+ sheets and scripts as possible from documents and templates.
275
+
276
+ Separating structure from presentation from behavior is important for
277
+ maintenance reasons. It is always more expensive to change HTML documents and
278
+ templates than it is to update style sheets and scripts.
279
+
280
+ ```
281
+ <!-- Not recommended -->
282
+ <!doctype html>
283
+ <title>HTML sucks</title>
284
+ <link rel="stylesheet" href="base.css" media="screen">
285
+ <link rel="stylesheet" href="grid.css" media="screen">
286
+ <link rel="stylesheet" href="print.css" media="print">
287
+ <h1 style="font-size: 1em;">HTML sucks</h1>
288
+ <p>I’ve read about this on a few sites but now I’m sure:
289
+ <u>HTML is stupid!!1</u>
290
+ <center>I can’t believe there’s no way to control the styling of
291
+ my website without doing everything all over again!</center>
292
+ ```
293
+
294
+ ```
295
+ <!-- Recommended -->
296
+ <!doctype html>
297
+ <title>My first CSS-only redesign</title>
298
+ <link rel="stylesheet" href="default.css">
299
+ <h1>My first CSS-only redesign</h1>
300
+ <p>I’ve read about this on a few sites but today I’m actually
301
+ doing it: separating concerns and avoiding anything in the HTML of
302
+ my website that is presentational.
303
+ <p>It’s awesome!
304
+ ```
305
+
306
+ #### Entity References
307
+
308
+ Do not use entity references.
309
+
310
+ There is no need to use entity references like `&mdash;`, `&rdquo;`, or
311
+ `&#x263a;`, assuming the same encoding (UTF-8) is used for files and editors as
312
+ well as among teams.
313
+
314
+ The only exceptions apply to characters with special meaning in HTML (like `<`
315
+ and `&`) as well as control or “invisible” characters (like no-break spaces).
316
+
317
+ ```
318
+ <!-- Not recommended -->
319
+ The currency symbol for the Euro is &ldquo;&eur;&rdquo;.
320
+ ```
321
+
322
+ ```
323
+ <!-- Recommended -->
324
+ The currency symbol for the Euro is “€”.
325
+ ```
326
+
327
+ #### Optional Tags
328
+
329
+ Omit optional tags (optional).
330
+
331
+ For file size optimization and scannability purposes, consider omitting optional
332
+ tags. The
333
+ [HTML5 specification](https://html.spec.whatwg.org/multipage/syntax.html#syntax-tag-omission)
334
+ defines what tags can be omitted.
335
+
336
+ (This approach may require a grace period to be established as a wider guideline
337
+ as it’s significantly different from what web developers are typically taught.
338
+ For consistency and simplicity reasons it’s best served omitting all optional
339
+ tags, not just a selection.)
340
+
341
+ ```
342
+ <!-- Not recommended -->
343
+ <!doctype html>
344
+ <html>
345
+ <head>
346
+ <title>Spending money, spending bytes</title>
347
+ </head>
348
+ <body>
349
+ <p>Sic.</p>
350
+ </body>
351
+ </html>
352
+ ```
353
+
354
+ ```
355
+ <!-- Recommended -->
356
+ <!doctype html>
357
+ <title>Saving money, saving bytes</title>
358
+ <p>Qed.
359
+ ```
360
+
361
+ #### `type` Attributes
362
+
363
+ Omit `type` attributes for style sheets and scripts.
364
+
365
+ Do not use `type` attributes for style sheets (unless not using CSS) and scripts
366
+ (unless not using JavaScript).
367
+
368
+ Specifying `type` attributes in these contexts is not necessary as HTML5 implies
369
+ [`text/css`](https://html.spec.whatwg.org/multipage/obsolete.html#attr-style-type)
370
+ and
371
+ [`text/javascript`](https://html.spec.whatwg.org/multipage/scripting.html#attr-script-type)
372
+ as defaults. This can be safely done even for older browsers.
373
+
374
+ ```
375
+ <!-- Not recommended -->
376
+ <link rel="stylesheet" href="https://www.google.com/css/maia.css"
377
+ type="text/css">
378
+ ```
379
+
380
+ ```
381
+ <!-- Recommended -->
382
+ <link rel="stylesheet" href="https://www.google.com/css/maia.css">
383
+ ```
384
+
385
+ ```
386
+ <!-- Not recommended -->
387
+ <script src="https://www.google.com/js/gweb/analytics/autotrack.js"
388
+ type="text/javascript"></script>
389
+ ```
390
+
391
+ ```
392
+ <!-- Recommended -->
393
+ <script src="https://www.google.com/js/gweb/analytics/autotrack.js"></script>
394
+ ```
395
+
396
+ #### `id` Attributes
397
+
398
+ Avoid unnecessary `id` attributes.
399
+
400
+ Prefer `class` attributes for styling and `data` attributes for scripting.
401
+
402
+ Where `id` attributes are strictly required, always include a hyphen in the
403
+ value to ensure it does not match the JavaScript identifier syntax, e.g. use
404
+ `user-profile` rather than just `profile` or `userProfile`.
405
+
406
+ When an element has an `id` attribute, browsers will make that available as a
407
+ [named property on the global `window` prototype](https://html.spec.whatwg.org/multipage/window-object.html#named-access-on-the-window-object),
408
+ which may cause unexpected behavior. While `id` attribute values containing a
409
+ hyphen are still available as property names, these cannot be referenced as
410
+ global JavaScript variables.
411
+
412
+ ```
413
+ <!-- Not recommended: `window.userProfile` will resolve to reference the <div> node -->
414
+ <div id="userProfile"></div>
415
+ ```
416
+
417
+ ```
418
+ <!-- Recommended: `id` attribute is required and its value includes a hyphen -->
419
+ <div aria-describedby="user-profile">
420
+
421
+ <div id="user-profile"></div>
422
+
423
+ </div>
424
+ ```
425
+
426
+ ### HTML Formatting Rules
427
+
428
+ #### General Formatting
429
+
430
+ Use a new line for every block, list, or table element, and indent every such
431
+ child element.
432
+
433
+ Independent of the styling of an element (as CSS allows elements to assume a
434
+ different role per `display` property), put every block, list, or table element
435
+ on a new line.
436
+
437
+ Also, indent them if they are child elements of a block, list, or table element.
438
+
439
+ (If you run into issues around whitespace between list items it’s acceptable to
440
+ put all `li` elements in one line. A linter is encouraged to throw a warning
441
+ instead of an error.)
442
+
443
+ ```
444
+ <blockquote>
445
+ <p><em>Space</em>, the final frontier.</p>
446
+ </blockquote>
447
+ ```
448
+
449
+ ```
450
+ <ul>
451
+ <li>Moe
452
+ <li>Larry
453
+ <li>Curly
454
+ </ul>
455
+ ```
456
+
457
+ ```
458
+ <table>
459
+ <thead>
460
+ <tr>
461
+ <th scope="col">Income
462
+ <th scope="col">Taxes
463
+ <tbody>
464
+ <tr>
465
+ <td>$ 5.00
466
+ <td>$ 4.50
467
+ </table>
468
+ ```
469
+
470
+ #### HTML Line-Wrapping
471
+
472
+ Break long lines (optional).
473
+
474
+ While there is no column limit recommendation for HTML, you may consider
475
+ wrapping long lines if it significantly improves readability.
476
+
477
+ When line-wrapping, each continuation line should be indented to distinguish
478
+ wrapped attributes from child elements. Lines should be wrapped consistently
479
+ within a project, ideally enforced by automated code formatting tools.
480
+
481
+ ```
482
+ <button
483
+ mat-icon-button
484
+ color="primary"
485
+ class="menu-button"
486
+ (click)="openMenu()"
487
+ >
488
+ <mat-icon>menu</mat-icon>
489
+ </button>
490
+ ```
491
+
492
+ ```
493
+ <button mat-icon-button color="primary" class="menu-button"
494
+ (click)="openMenu()">
495
+ <mat-icon>menu</mat-icon>
496
+ </button>
497
+ ```
498
+
499
+ ```
500
+ <button
501
+ mat-icon-button
502
+ color="primary"
503
+ class="menu-button"
504
+ (click)="openMenu()">
505
+ <mat-icon>menu</mat-icon>
506
+ </button>
507
+ ```
508
+
509
+ ```
510
+ <button mat-icon-button
511
+ color="primary"
512
+ class="menu-button"
513
+ (click)="openMenu()">
514
+ <mat-icon>menu</mat-icon>
515
+ </button>
516
+ ```
517
+
518
+ #### HTML Quotation Marks
519
+
520
+ When quoting attributes values, use double quotation marks.
521
+
522
+ Use double (`""`) rather than single quotation marks (`''`) around attribute
523
+ values.
524
+
525
+ ```
526
+ <!-- Not recommended -->
527
+ <a class='maia-button maia-button-secondary'>Sign in</a>
528
+ ```
529
+
530
+ ```
531
+ <!-- Recommended -->
532
+ <a class="maia-button maia-button-secondary">Sign in</a>
533
+ ```
534
+
535
+ ## CSS
536
+
537
+ ### CSS Style Rules
538
+
539
+ #### CSS Validity
540
+
541
+ Use valid CSS where possible.
542
+
543
+ Unless dealing with CSS validator bugs or requiring proprietary syntax, use
544
+ valid CSS code.
545
+
546
+ Use tools such as the
547
+ [W3C CSS validator](https://jigsaw.w3.org/css-validator/)
548
+ to test.
549
+
550
+ Using valid CSS is a measurable baseline quality attribute that allows to spot
551
+ CSS code that may not have any effect and can be removed, and that ensures
552
+ proper CSS usage.
553
+
554
+ #### Class Naming
555
+
556
+ Use meaningful or generic class names.
557
+
558
+ Instead of presentational or cryptic names, always use class names that reflect
559
+ the purpose of the element in question, or that are otherwise generic.
560
+
561
+ Names that are specific and reflect the purpose of the element should be
562
+ preferred as these are most understandable and the least likely to change.
563
+
564
+ Generic names are simply a fallback for elements that have no particular or no
565
+ meaning different from their siblings. They are typically needed as “helpers.”
566
+
567
+ Using functional or generic names reduces the probability of unnecessary
568
+ document or template changes.
569
+
570
+ ```
571
+ /* Not recommended: meaningless */
572
+ .yee-1901 {}
573
+
574
+ /* Not recommended: presentational */
575
+ .button-green {}
576
+ .clear {}
577
+ ```
578
+
579
+ ```
580
+ /* Recommended: specific */
581
+ .gallery {}
582
+ .login {}
583
+ .video {}
584
+
585
+ /* Recommended: generic */
586
+ .aux {}
587
+ .alt {}
588
+ ```
589
+
590
+ #### Class Name Style
591
+
592
+ Use class names that are as short as possible but as long as necessary.
593
+
594
+ Try to convey what a class is about while being as brief as possible.
595
+
596
+ Using class names this way contributes to acceptable levels of understandability
597
+ and code efficiency.
598
+
599
+ ```
600
+ /* Not recommended */
601
+ .navigation {}
602
+ .atr {}
603
+ ```
604
+
605
+ ```
606
+ /* Recommended */
607
+ .nav {}
608
+ .author {}
609
+ ```
610
+
611
+ #### Class Name Delimiters
612
+
613
+ Separate words in class names by a hyphen.
614
+
615
+ Do not concatenate words and abbreviations in selectors by any characters
616
+ (including none at all) other than hyphens, in order to improve understanding
617
+ and scannability.
618
+
619
+ ```
620
+ /* Not recommended: does not separate the words “demo” and “image” */
621
+ .demoimage {}
622
+
623
+ /* Not recommended: uses underscore instead of hyphen */
624
+ .error_status {}
625
+ ```
626
+
627
+ ```
628
+ /* Recommended */
629
+ .video-id {}
630
+ .ads-sample {}
631
+ ```
632
+
633
+ #### Prefixes
634
+
635
+ Prefix selectors with an application-specific prefix (optional).
636
+
637
+ In large projects as well as for code that gets embedded in other projects or on
638
+ external sites use prefixes (as namespaces) for class names. Use short, unique
639
+ identifiers followed by a dash.
640
+
641
+ Using namespaces helps preventing naming conflicts and can make maintenance
642
+ easier, for example in search and replace operations.
643
+
644
+ ```
645
+ .adw-help {} /* AdWords */
646
+ .maia-note {} /* Maia */
647
+ ```
648
+
649
+ #### Type Selectors
650
+
651
+ Avoid qualifying class names with type selectors.
652
+
653
+ Unless necessary (for example with helper classes), do not use element names in
654
+ conjunction with classes.
655
+
656
+ Avoiding unnecessary ancestor selectors is useful for
657
+ [performance reasons](http://www.stevesouders.com/blog/2009/06/18/simplifying-css-selectors/).
658
+
659
+ ```
660
+ /* Not recommended */
661
+ ul.example {}
662
+ div.error {}
663
+ ```
664
+
665
+ ```
666
+ /* Recommended */
667
+ .example {}
668
+ .error {}
669
+ ```
670
+
671
+ #### ID Selectors
672
+
673
+ Avoid ID selectors.
674
+
675
+ ID attributes are expected to be unique across an entire page, which is
676
+ difficult to guarantee when a page contains many components worked on by many
677
+ different engineers. Class selectors should be preferred in all situations.
678
+
679
+ ```
680
+ /* Not recommended */
681
+ #example {}
682
+ ```
683
+
684
+ ```
685
+ /* Recommended */
686
+ .example {}
687
+ ```
688
+
689
+ #### Shorthand Properties
690
+
691
+ Use shorthand properties where possible.
692
+
693
+ CSS offers a variety of
694
+ [shorthand](https://www.w3.org/TR/CSS21/about.html#shorthand)
695
+ properties (like `font`) that should be used whenever possible, even in cases
696
+ where only one value is explicitly set.
697
+
698
+ Using shorthand properties is useful for code efficiency and understandability.
699
+
700
+ ```
701
+ /* Not recommended */
702
+ border-top-style: none;
703
+ font-family: palatino, georgia, serif;
704
+ font-size: 100%;
705
+ line-height: 1.6;
706
+ padding-bottom: 2em;
707
+ padding-left: 1em;
708
+ padding-right: 1em;
709
+ padding-top: 0;
710
+ ```
711
+
712
+ ```
713
+ /* Recommended */
714
+ border-top: 0;
715
+ font: 100%/1.6 palatino, georgia, serif;
716
+ padding: 0 1em 2em;
717
+ ```
718
+
719
+ #### 0 and Units
720
+
721
+ Omit unit specification after “0” values, unless required.
722
+
723
+ Do not use units after `0` values unless they are required.
724
+
725
+ ```
726
+ flex: 0px; /* This flex-basis component requires a unit. */
727
+ flex: 1 1 0px; /* Not ambiguous without the unit, but needed in IE11. */
728
+ margin: 0;
729
+ padding: 0;
730
+ ```
731
+
732
+ #### Leading 0s
733
+
734
+ Always include leading “0”s in values.
735
+
736
+ Put `0`s in front of values or lengths between -1 and 1.
737
+
738
+ ```
739
+ font-size: 0.8em;
740
+ ```
741
+
742
+ #### Hexadecimal Notation
743
+
744
+ Use 3 character hexadecimal notation where possible.
745
+
746
+ For color values that permit it, 3 character hexadecimal notation is shorter and
747
+ more succinct.
748
+
749
+ ```
750
+ /* Not recommended */
751
+ color: #eebbcc;
752
+ ```
753
+
754
+ ```
755
+ /* Recommended */
756
+ color: #ebc;
757
+ ```
758
+
759
+ #### Important Declarations
760
+
761
+ Avoid using `!important` declarations.
762
+
763
+ These declarations break the natural cascade of CSS and make it difficult to
764
+ reason about and compose styles. Use
765
+ [selector specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity)
766
+ to override properties instead.
767
+
768
+ ```
769
+ /* Not recommended */
770
+ .example {
771
+ font-weight: bold !important;
772
+ }
773
+ ```
774
+
775
+ ```
776
+ /* Recommended */
777
+ .example {
778
+ font-weight: bold;
779
+ }
780
+ ```
781
+
782
+ #### Hacks
783
+
784
+ Avoid user agent detection as well as CSS “hacks”—try a different approach
785
+ first.
786
+
787
+ It’s tempting to address styling differences over user agent detection or
788
+ special CSS filters, workarounds, and hacks. Both approaches should be
789
+ considered last resort in order to achieve and maintain an efficient and
790
+ manageable code base. Put another way, giving detection and hacks a free pass
791
+ will hurt projects in the long run as projects tend to take the way of least
792
+ resistance. That is, allowing and making it easy to use detection and hacks
793
+ means using detection and hacks more frequently—and more frequently is too
794
+ frequently.
795
+
796
+ ### CSS Formatting Rules
797
+
798
+ #### Declaration Order
799
+
800
+ Alphabetize declarations (optional).
801
+
802
+ Sort declarations consistently within a project. In the absence of tooling to
803
+ automate and enforce a consistent sort order, consider putting declarations in
804
+ alphabetical order in order to achieve consistent code in a way that is easy to
805
+ learn, remember, and manually maintain.
806
+
807
+ Ignore vendor-specific prefixes for sorting purposes. However, multiple
808
+ vendor-specific prefixes for a certain CSS property should be kept sorted (e.g.
809
+ -moz prefix comes before -webkit).
810
+
811
+ ```
812
+ background: fuchsia;
813
+ border: 1px solid;
814
+ -moz-border-radius: 4px;
815
+ -webkit-border-radius: 4px;
816
+ border-radius: 4px;
817
+ color: black;
818
+ text-align: center;
819
+ text-indent: 2em;
820
+ ```
821
+
822
+ #### Block Content Indentation
823
+
824
+ Indent all block content.
825
+
826
+ Indent all
827
+ [block content](https://www.w3.org/TR/CSS21/syndata.html#block),
828
+ that is rules within rules as well as declarations, so to reflect hierarchy and
829
+ improve understanding.
830
+
831
+ ```
832
+ @media screen, projection {
833
+
834
+ html {
835
+ background: #fff;
836
+ color: #444;
837
+ }
838
+
839
+ }
840
+ ```
841
+
842
+ #### Declaration Stops
843
+
844
+ Use a semicolon after every declaration.
845
+
846
+ End every declaration with a semicolon for consistency and extensibility
847
+ reasons.
848
+
849
+ ```
850
+ /* Not recommended */
851
+ .test {
852
+ display: block;
853
+ height: 100px
854
+ }
855
+ ```
856
+
857
+ ```
858
+ /* Recommended */
859
+ .test {
860
+ display: block;
861
+ height: 100px;
862
+ }
863
+ ```
864
+
865
+ #### Property Name Stops
866
+
867
+ Use a space after a property name’s colon.
868
+
869
+ Always use a single space between property and value (but no space between
870
+ property and colon) for consistency reasons.
871
+
872
+ ```
873
+ /* Not recommended */
874
+ h3 {
875
+ font-weight:bold;
876
+ }
877
+ ```
878
+
879
+ ```
880
+ /* Recommended */
881
+ h3 {
882
+ font-weight: bold;
883
+ }
884
+ ```
885
+
886
+ #### Declaration Block Separation
887
+
888
+ Use a space between the last selector and the declaration block.
889
+
890
+ Always use a single space between the last selector and the opening brace that
891
+ begins the
892
+ [declaration block](https://www.w3.org/TR/CSS21/syndata.html#rule-sets).
893
+
894
+ The opening brace should be on the same line as the last selector in a given
895
+ rule.
896
+
897
+ ```
898
+ /* Not recommended: missing space */
899
+ .video{
900
+ margin-top: 1em;
901
+ }
902
+
903
+ /* Not recommended: unnecessary line break */
904
+ .video
905
+ {
906
+ margin-top: 1em;
907
+ }
908
+ ```
909
+
910
+ ```
911
+ /* Recommended */
912
+ .video {
913
+ margin-top: 1em;
914
+ }
915
+ ```
916
+
917
+ #### Selector and Declaration Separation
918
+
919
+ Separate selectors and declarations by new lines.
920
+
921
+ Always start a new line for each selector and declaration.
922
+
923
+ ```
924
+ /* Not recommended */
925
+ a:focus, a:active {
926
+ position: relative; top: 1px;
927
+ }
928
+ ```
929
+
930
+ ```
931
+ /* Recommended */
932
+ h1,
933
+ h2,
934
+ h3 {
935
+ font-weight: normal;
936
+ line-height: 1.2;
937
+ }
938
+ ```
939
+
940
+ #### Rule Separation
941
+
942
+ Separate rules by new lines.
943
+
944
+ Always put a blank line (two line breaks) between rules.
945
+
946
+ ```
947
+ html {
948
+ background: #fff;
949
+ }
950
+
951
+ body {
952
+ margin: auto;
953
+ width: 50%;
954
+ }
955
+ ```
956
+
957
+ #### CSS Quotation Marks
958
+
959
+ Use single (`''`) rather than double (`""`) quotation marks for attribute
960
+ selectors and property values.
961
+
962
+ Do not use quotation marks in URI values (`url()`).
963
+
964
+ Exception: If you do need to use the `@charset` rule, use double quotation
965
+ marks—[single quotation marks are not permitted](https://www.w3.org/TR/CSS21/syndata.html#charset).
966
+
967
+ ```
968
+ /* Not recommended */
969
+ @import url("https://www.google.com/css/maia.css");
970
+
971
+ html {
972
+ font-family: "open sans", arial, sans-serif;
973
+ }
974
+ ```
975
+
976
+ ```
977
+ /* Recommended */
978
+ @import url(https://www.google.com/css/maia.css);
979
+
980
+ html {
981
+ font-family: 'open sans', arial, sans-serif;
982
+ }
983
+ ```
984
+
985
+ ### CSS Meta Rules
986
+
987
+ #### Section Comments
988
+
989
+ Group sections by a section comment (optional).
990
+
991
+ If possible, group style sheet sections together by using comments. Separate
992
+ sections with new lines.
993
+
994
+ ```
995
+ /* Header */
996
+
997
+ .adw-header {}
998
+
999
+ /* Footer */
1000
+
1001
+ .adw-footer {}
1002
+
1003
+ /* Gallery */
1004
+
1005
+ .adw-gallery {}
1006
+ ```
1007
+
1008
+ ## Parting Words
1009
+
1010
+ *Be consistent.*
1011
+
1012
+ If you’re editing code, take a few minutes to look at the code around you and
1013
+ determine its style. If they use spaces around all their arithmetic operators,
1014
+ you should too. If their comments have little boxes of hash marks around them,
1015
+ make your comments have little boxes of hash marks around them too.
1016
+
1017
+ The point of having style guidelines is to have a common vocabulary of coding so
1018
+ people can concentrate on what you’re saying rather than on how you’re saying
1019
+ it. We present global style rules here so people know the vocabulary, but local
1020
+ style is also important. If code you add to a file looks drastically different
1021
+ from the existing code around it, it throws readers out of their rhythm when
1022
+ they go to read it. Avoid this.