mirror of
https://github.com/google/styleguide.git
synced 2024-03-22 13:11:43 +08:00
Sync.
This commit is contained in:
parent
ded2b0a246
commit
1e1b50bf73
135
htmlcssguide.xml
135
htmlcssguide.xml
|
@ -1,9 +1,8 @@
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<?xml-stylesheet type="text/xsl" href="styleguide.xsl"?>
|
|
||||||
<GUIDE title="Google HTML/CSS Style Guide">
|
<GUIDE title="Google HTML/CSS Style Guide">
|
||||||
<p class="revision">
|
<p class="revision">
|
||||||
|
|
||||||
Revision 2.1
|
Revision 2.2
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<OVERVIEW>
|
<OVERVIEW>
|
||||||
|
@ -13,12 +12,12 @@
|
||||||
This style guide contains many details that are initially
|
This style guide contains many details that are initially
|
||||||
hidden from view. They are marked by the triangle icon, which you
|
hidden from view. They are marked by the triangle icon, which you
|
||||||
see here on your left. Click it now.
|
see here on your left. Click it now.
|
||||||
You should see “Hooray” appear below.
|
You should see “Hooray” appear below.
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>
|
<p>
|
||||||
Hooray! Now you know you can expand points to get more
|
Hooray! Now you know you can expand points to get more
|
||||||
details. Alternatively, there’s a “toggle all” at the
|
details. Alternatively, there’s a “toggle all” at the
|
||||||
top of this document.
|
top of this document.
|
||||||
</p>
|
</p>
|
||||||
</BODY>
|
</BODY>
|
||||||
|
@ -52,8 +51,8 @@
|
||||||
files are not available over both protocols.
|
files are not available over both protocols.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Omitting the protocol—which makes the URL
|
Omitting the protocol—which makes the URL
|
||||||
relative—prevents mixed content issues and results in
|
relative—prevents mixed content issues and results in
|
||||||
minor file size savings.
|
minor file size savings.
|
||||||
</p>
|
</p>
|
||||||
<BAD_CODE_SNIPPET>
|
<BAD_CODE_SNIPPET>
|
||||||
|
@ -88,7 +87,7 @@
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>
|
<p>
|
||||||
Don’t use tabs or mix tabs and spaces for indentation.
|
Don’t use tabs or mix tabs and spaces for indentation.
|
||||||
</p>
|
</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
<ul>
|
<ul>
|
||||||
|
@ -109,7 +108,7 @@
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>
|
<p>
|
||||||
All code has to be lowercase: this applies to element names,
|
All code has to be lowercase: This applies to element names,
|
||||||
attributes, attribute values (unless
|
attributes, attribute values (unless
|
||||||
text/<code>CDATA</code>), selectors, properties, and
|
text/<code>CDATA</code>), selectors, properties, and
|
||||||
property values (with the exception of strings).
|
property values (with the exception of strings).
|
||||||
|
@ -173,7 +172,7 @@
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>
|
<p>
|
||||||
Use comments to explain code: what does it cover, what
|
Use comments to explain code: What does it cover, what
|
||||||
purpose does it serve, why is respective solution used or
|
purpose does it serve, why is respective solution used or
|
||||||
preferred?
|
preferred?
|
||||||
</p>
|
</p>
|
||||||
|
@ -181,7 +180,7 @@
|
||||||
(This item is optional as it is not deemed a realistic
|
(This item is optional as it is not deemed a realistic
|
||||||
expectation to always demand fully documented code. Mileage
|
expectation to always demand fully documented code. Mileage
|
||||||
may vary heavily for HTML and CSS code and depends on the
|
may vary heavily for HTML and CSS code and depends on the
|
||||||
project’s complexity.)
|
project’s complexity.)
|
||||||
</p>
|
</p>
|
||||||
</BODY>
|
</BODY>
|
||||||
</STYLEPOINT>
|
</STYLEPOINT>
|
||||||
|
@ -230,11 +229,15 @@
|
||||||
<code><!DOCTYPE html></code>.
|
<code><!DOCTYPE html></code>.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
(It is recommended to use HTML, as <code>text/html</code>. Do not use
|
(It’s recommended to use HTML, as <code>text/html</code>. Do not use
|
||||||
XHTML. XHTML, as <a href="http://hixie.ch/advocacy/xhtml"><code>application/xhtml+xml</code></a>,
|
XHTML. XHTML, as <a href="http://hixie.ch/advocacy/xhtml"><code>application/xhtml+xml</code></a>,
|
||||||
lacks both browser and infrastructure support and offers
|
lacks both browser and infrastructure support and offers
|
||||||
less room for optimization than HTML.)
|
less room for optimization than HTML.)
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
Although fine with HTML, do not close void elements, i.e. write
|
||||||
|
<code><br></code>, not <code><br /></code>.
|
||||||
|
</p>
|
||||||
</BODY>
|
</BODY>
|
||||||
</STYLEPOINT>
|
</STYLEPOINT>
|
||||||
<STYLEPOINT title="HTML validity">
|
<STYLEPOINT title="HTML validity">
|
||||||
|
@ -276,7 +279,7 @@
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>
|
<p>
|
||||||
Use elements (sometimes incorrectly called “tags”) for what
|
Use elements (sometimes incorrectly called “tags”) for what
|
||||||
they have been created for. For example, use heading
|
they have been created for. For example, use heading
|
||||||
elements for headings, <code>p</code> elements for
|
elements for headings, <code>p</code> elements for
|
||||||
paragraphs, <code>a</code> elements for anchors, etc.
|
paragraphs, <code>a</code> elements for anchors, etc.
|
||||||
|
@ -310,7 +313,7 @@
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Providing alternative contents is important for
|
Providing alternative contents is important for
|
||||||
accessibility reasons: a blind user has few cues to tell
|
accessibility reasons: A blind user has few cues to tell
|
||||||
what an image is about without <code>@alt</code>, and other
|
what an image is about without <code>@alt</code>, and other
|
||||||
users may have no way of understanding what video or audio
|
users may have no way of understanding what video or audio
|
||||||
contents are about either.
|
contents are about either.
|
||||||
|
@ -369,9 +372,9 @@
|
||||||
<link rel="stylesheet" href="grid.css" media="screen">
|
<link rel="stylesheet" href="grid.css" media="screen">
|
||||||
<link rel="stylesheet" href="print.css" media="print">
|
<link rel="stylesheet" href="print.css" media="print">
|
||||||
<h1 style="font-size: 1em;">HTML sucks</h1>
|
<h1 style="font-size: 1em;">HTML sucks</h1>
|
||||||
<p>I’ve read about this on a few sites but now I’m sure:
|
<p>I’ve read about this on a few sites but now I’m sure:
|
||||||
<u>HTML is stupid!!1</u>
|
<u>HTML is stupid!!1</u>
|
||||||
<center>I can’t believe there’s no way to control the styling of
|
<center>I can’t believe there’s no way to control the styling of
|
||||||
my website without doing everything all over again!</center>
|
my website without doing everything all over again!</center>
|
||||||
</BAD_CODE_SNIPPET>
|
</BAD_CODE_SNIPPET>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
|
@ -380,10 +383,10 @@
|
||||||
<title>My first CSS-only redesign</title>
|
<title>My first CSS-only redesign</title>
|
||||||
<link rel="stylesheet" href="default.css">
|
<link rel="stylesheet" href="default.css">
|
||||||
<h1>My first CSS-only redesign</h1>
|
<h1>My first CSS-only redesign</h1>
|
||||||
<p>I’ve read about this on a few sites but today I’m actually
|
<p>I’ve read about this on a few sites but today I’m actually
|
||||||
doing it: separating concerns and avoiding anything in the HTML of
|
doing it: separating concerns and avoiding anything in the HTML of
|
||||||
my website that is presentational.
|
my website that is presentational.
|
||||||
<p>It’s awesome!
|
<p>It’s awesome!
|
||||||
</CODE_SNIPPET>
|
</CODE_SNIPPET>
|
||||||
</BODY>
|
</BODY>
|
||||||
</STYLEPOINT>
|
</STYLEPOINT>
|
||||||
|
@ -402,7 +405,7 @@
|
||||||
<p>
|
<p>
|
||||||
The only exceptions apply to characters with special meaning
|
The only exceptions apply to characters with special meaning
|
||||||
in HTML (like <code><</code> and <code>&</code>) as
|
in HTML (like <code><</code> and <code>&</code>) as
|
||||||
well as control or “invisible” characters (like no-break
|
well as control or “invisible” characters (like no-break
|
||||||
spaces).
|
spaces).
|
||||||
</p>
|
</p>
|
||||||
<BAD_CODE_SNIPPET>
|
<BAD_CODE_SNIPPET>
|
||||||
|
@ -411,7 +414,7 @@
|
||||||
</BAD_CODE_SNIPPET>
|
</BAD_CODE_SNIPPET>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
<!-- Recommended -->
|
<!-- Recommended -->
|
||||||
The currency symbol for the Euro is “€”.
|
The currency symbol for the Euro is “€”.
|
||||||
</CODE_SNIPPET>
|
</CODE_SNIPPET>
|
||||||
</BODY>
|
</BODY>
|
||||||
</STYLEPOINT>
|
</STYLEPOINT>
|
||||||
|
@ -428,9 +431,9 @@
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
(This approach may require a grace period to be established
|
(This approach may require a grace period to be established
|
||||||
as a wider guideline as it is significantly different
|
as a wider guideline as it’s significantly different
|
||||||
from what web developers are typically taught. For
|
from what web developers are typically taught. For
|
||||||
consistency and simplicity reasons it is best served
|
consistency and simplicity reasons it’s best served
|
||||||
omitting all optional tags, not just a selection.)
|
omitting all optional tags, not just a selection.)
|
||||||
</p>
|
</p>
|
||||||
<BAD_CODE_SNIPPET>
|
<BAD_CODE_SNIPPET>
|
||||||
|
@ -512,7 +515,7 @@
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
(If you run into issues around whitespace between list items
|
(If you run into issues around whitespace between list items
|
||||||
it is acceptable to put all <code>li</code> elements in one
|
it’s acceptable to put all <code>li</code> elements in one
|
||||||
line. A linter is encouraged to throw a warning instead of
|
line. A linter is encouraged to throw a warning instead of
|
||||||
an error.)
|
an error.)
|
||||||
</p>
|
</p>
|
||||||
|
@ -542,6 +545,25 @@
|
||||||
</CODE_SNIPPET>
|
</CODE_SNIPPET>
|
||||||
</BODY>
|
</BODY>
|
||||||
</STYLEPOINT>
|
</STYLEPOINT>
|
||||||
|
<STYLEPOINT title="HTML quotation marks">
|
||||||
|
<SUMMARY>
|
||||||
|
Use double quotation marks for attribute values where necessary.
|
||||||
|
</SUMMARY>
|
||||||
|
<BODY>
|
||||||
|
<p>
|
||||||
|
When quoting attribute values, use double (<code>""</code>) rather
|
||||||
|
than single quotation marks (<code>''</code>).
|
||||||
|
</p>
|
||||||
|
<BAD_CODE_SNIPPET>
|
||||||
|
<!-- Not recommended -->
|
||||||
|
<a class='maia-button maia-button-secondary'>Sign in</a>
|
||||||
|
</BAD_CODE_SNIPPET>
|
||||||
|
<CODE_SNIPPET>
|
||||||
|
<!-- Recommended -->
|
||||||
|
<a class="maia-button maia-button-secondary">Sign in</a>
|
||||||
|
</CODE_SNIPPET>
|
||||||
|
</BODY>
|
||||||
|
</STYLEPOINT>
|
||||||
</CATEGORY>
|
</CATEGORY>
|
||||||
|
|
||||||
<CATEGORY title="CSS Style Rules">
|
<CATEGORY title="CSS Style Rules">
|
||||||
|
@ -585,7 +607,7 @@
|
||||||
<p>
|
<p>
|
||||||
Generic names are simply a fallback for elements that have no
|
Generic names are simply a fallback for elements that have no
|
||||||
particular or no meaning different from their siblings. They are
|
particular or no meaning different from their siblings. They are
|
||||||
typically needed as “helpers.”
|
typically needed as “helpers.”
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Using functional or generic names reduces the probability of
|
Using functional or generic names reduces the probability of
|
||||||
|
@ -700,7 +722,7 @@
|
||||||
</STYLEPOINT>
|
</STYLEPOINT>
|
||||||
<STYLEPOINT title="0 and units">
|
<STYLEPOINT title="0 and units">
|
||||||
<SUMMARY>
|
<SUMMARY>
|
||||||
Omit unit specification after “0” values.
|
Omit unit specification after “0” values.
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>
|
<p>
|
||||||
|
@ -715,7 +737,7 @@
|
||||||
</STYLEPOINT>
|
</STYLEPOINT>
|
||||||
<STYLEPOINT title="Leading 0s">
|
<STYLEPOINT title="Leading 0s">
|
||||||
<SUMMARY>
|
<SUMMARY>
|
||||||
Omit leading “0”s in values.
|
Omit leading “0”s in values.
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>
|
<p>
|
||||||
|
@ -727,20 +749,6 @@
|
||||||
</CODE_SNIPPET>
|
</CODE_SNIPPET>
|
||||||
</BODY>
|
</BODY>
|
||||||
</STYLEPOINT>
|
</STYLEPOINT>
|
||||||
<STYLEPOINT title="Quotation marks in URI values">
|
|
||||||
<SUMMARY>
|
|
||||||
Omit quotation marks in URI values.
|
|
||||||
</SUMMARY>
|
|
||||||
<BODY>
|
|
||||||
<p>
|
|
||||||
Do not use quotation marks (<code>""</code>,
|
|
||||||
<code>''</code>) with <code>url()</code>.
|
|
||||||
</p>
|
|
||||||
<CODE_SNIPPET>
|
|
||||||
@import url(//www.google.com/css/go.css);
|
|
||||||
</CODE_SNIPPET>
|
|
||||||
</BODY>
|
|
||||||
</STYLEPOINT>
|
|
||||||
<STYLEPOINT title="Hexadecimal notation">
|
<STYLEPOINT title="Hexadecimal notation">
|
||||||
<SUMMARY>
|
<SUMMARY>
|
||||||
Use 3 character hexadecimal notation where possible.
|
Use 3 character hexadecimal notation where possible.
|
||||||
|
@ -795,7 +803,7 @@
|
||||||
in order to improve understanding and scannability.
|
in order to improve understanding and scannability.
|
||||||
</p>
|
</p>
|
||||||
<BAD_CODE_SNIPPET>
|
<BAD_CODE_SNIPPET>
|
||||||
/* Not recommended: does not separate the words “demo” and “image” */
|
/* Not recommended: does not separate the words “demo” and “image” */
|
||||||
.demoimage {}
|
.demoimage {}
|
||||||
|
|
||||||
/* Not recommended: uses underscore instead of hyphen */
|
/* Not recommended: uses underscore instead of hyphen */
|
||||||
|
@ -810,12 +818,12 @@
|
||||||
</STYLEPOINT>
|
</STYLEPOINT>
|
||||||
<STYLEPOINT title="Hacks">
|
<STYLEPOINT title="Hacks">
|
||||||
<SUMMARY>
|
<SUMMARY>
|
||||||
Avoid user agent detection as well as CSS “hacks”—try a different
|
Avoid user agent detection as well as CSS “hacks”—try a different
|
||||||
approach first.
|
approach first.
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>
|
<p>
|
||||||
It is tempting to address styling differences over user
|
It’s tempting to address styling differences over user
|
||||||
agent detection or special CSS filters, workarounds, and
|
agent detection or special CSS filters, workarounds, and
|
||||||
hacks. Both approaches should be considered last resort in
|
hacks. Both approaches should be considered last resort in
|
||||||
order to achieve and maintain an efficient and manageable
|
order to achieve and maintain an efficient and manageable
|
||||||
|
@ -823,7 +831,7 @@
|
||||||
free pass will hurt projects in the long run as projects
|
free pass will hurt projects in the long run as projects
|
||||||
tend to take the way of least resistance. That is, allowing
|
tend to take the way of least resistance. That is, allowing
|
||||||
and making it easy to use detection and hacks means using
|
and making it easy to use detection and hacks means using
|
||||||
detection and hacks more frequently—and more frequently
|
detection and hacks more frequently—and more frequently
|
||||||
is too frequently.
|
is too frequently.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
@ -909,7 +917,7 @@
|
||||||
</STYLEPOINT>
|
</STYLEPOINT>
|
||||||
<STYLEPOINT title="Property name stops">
|
<STYLEPOINT title="Property name stops">
|
||||||
<SUMMARY>
|
<SUMMARY>
|
||||||
Use a space after a property name’s colon.
|
Use a space after a property name’s colon.
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>
|
<p>
|
||||||
|
@ -975,6 +983,35 @@
|
||||||
</CODE_SNIPPET>
|
</CODE_SNIPPET>
|
||||||
</BODY>
|
</BODY>
|
||||||
</STYLEPOINT>
|
</STYLEPOINT>
|
||||||
|
<STYLEPOINT title="CSS quotation marks">
|
||||||
|
<SUMMARY>
|
||||||
|
Use single quotation marks for attribute selectors and property values
|
||||||
|
where necessary.
|
||||||
|
</SUMMARY>
|
||||||
|
<BODY>
|
||||||
|
<p>
|
||||||
|
When quoting attribute selectors and property values, use single
|
||||||
|
(<code>''</code>) rather than double (<code>""</code>) quotation
|
||||||
|
marks. Do not use quotation marks in URI values (<code>url()</code>).
|
||||||
|
</p>
|
||||||
|
<BAD_CODE_SNIPPET>
|
||||||
|
/* Not recommended */
|
||||||
|
@import url("//www.google.com/css/maia.css");
|
||||||
|
|
||||||
|
html {
|
||||||
|
font-family: "open sans", arial, sans-serif;
|
||||||
|
}
|
||||||
|
</BAD_CODE_SNIPPET>
|
||||||
|
<CODE_SNIPPET>
|
||||||
|
/* Recommended */
|
||||||
|
@import url(//www.google.com/css/maia.css);
|
||||||
|
|
||||||
|
html {
|
||||||
|
font-family: 'open sans', arial, sans-serif;
|
||||||
|
}
|
||||||
|
</CODE_SNIPPET>
|
||||||
|
</BODY>
|
||||||
|
</STYLEPOINT>
|
||||||
</CATEGORY>
|
</CATEGORY>
|
||||||
|
|
||||||
<CATEGORY title="CSS Meta Rules">
|
<CATEGORY title="CSS Meta Rules">
|
||||||
|
@ -985,7 +1022,7 @@
|
||||||
</SUMMARY>
|
</SUMMARY>
|
||||||
<BODY>
|
<BODY>
|
||||||
<p>
|
<p>
|
||||||
If possible, group style sheets sections together by using
|
If possible, group style sheet sections together by using
|
||||||
comments. Separate sections with new lines.
|
comments. Separate sections with new lines.
|
||||||
</p>
|
</p>
|
||||||
<CODE_SNIPPET>
|
<CODE_SNIPPET>
|
||||||
|
@ -1010,7 +1047,7 @@
|
||||||
<em>Be consistent.</em>
|
<em>Be consistent.</em>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
If you’re editing code, take a few minutes to look at the code
|
If you’re editing code, take a few minutes to look at the code
|
||||||
around you and determine its style. If they use spaces around
|
around you and determine its style. If they use spaces around
|
||||||
all their arithmetic operators, you should too. If their
|
all their arithmetic operators, you should too. If their
|
||||||
comments have little boxes of hash marks around them, make your
|
comments have little boxes of hash marks around them, make your
|
||||||
|
@ -1018,8 +1055,8 @@
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
The point of having style guidelines is to have a common vocabulary
|
The point of having style guidelines is to have a common vocabulary
|
||||||
of coding so people can concentrate on what you’re saying rather
|
of coding so people can concentrate on what you’re saying rather
|
||||||
than on how you’re saying it. We present global style rules here so
|
than on how you’re saying it. We present global style rules here so
|
||||||
people know the vocabulary, but local style is also important. If
|
people know the vocabulary, but local style is also important. If
|
||||||
code you add to a file looks drastically different from the existing
|
code you add to a file looks drastically different from the existing
|
||||||
code around it, it throws readers out of their rhythm when they go to
|
code around it, it throws readers out of their rhythm when they go to
|
||||||
|
@ -1028,7 +1065,7 @@
|
||||||
</PARTING_WORDS>
|
</PARTING_WORDS>
|
||||||
|
|
||||||
<p align="right">
|
<p align="right">
|
||||||
Revision 2.1
|
Revision 2.2
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
</GUIDE>
|
</GUIDE>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user