Code Better with the Google HTML/CSS Style Guide (9 Rules)
Did you know Google publishes an HTML/CSS Style Guide, the same rules its own developers follow? We all edit HTML and CSS on our blogs, but often without any consistent style. Following the Google HTML CSS style guide makes your code easier to read, faster to debug, and simpler for others (or future you) to maintain. I’ve been writing HTML and CSS for over two decades, and these are the rules from the guide I still use every day.

Quick answer: Google’s HTML/CSS Style Guide recommends indenting by 2 spaces (no tabs), using lowercase everywhere, using HTTPS for embedded resources, using CSS shorthand, short hex colours, no units after zero, meaningful hyphenated class names, alphabetical declarations, and validating your code. Tools like Prettier and Stylelint can enforce most of these automatically.
Table of Contents
Why follow a style guide?
Clean, consistent code isn’t just about looks. When every file follows the same rules, you can spot mistakes faster, compare changes easily, and pick up code you wrote years ago without confusion. Google keeps its style guides on GitHub for HTML/CSS, JavaScript, TypeScript, Python, Java, C++, Shell and more. The HTML/CSS guide takes about ten minutes to read.
9 coding rules from the Google HTML CSS style guide
1. Indent by 2 spaces
Use two spaces per indent level, not tabs:
<aside>
<div class="box">
<p>It's all about style</p>
</div>
</aside>2. Use only lowercase
Element names, attributes, selectors, properties and values (except strings) should all be lowercase:
color: #e5e5e5; /* not #E5E5E5 */3. Use 3-character hex colours where possible
color: #ebc; /* not #eebbcc */4. Use CSS shorthand
Shorthand properties are shorter and easier to read, and smaller files help CSS load faster:
/* Instead of this */
padding-bottom: 1em;
padding-left: 1em;
padding-right: 1em;
padding-top: 1em;
/* Write this */
padding: 1em;5. Don’t add units after zero
margin: 0; /* not 0px */6. Put declarations in alphabetical order
Sorting properties alphabetically makes them quicker to find and avoids duplicates:
.box {
background: #fff;
border: 1px solid #ccc;
color: #000;
text-transform: uppercase;
}
h1,
h2,
h3 {
color: #000;
}Notice the other good habits in that code: block contents indented, a space after each colon, a semicolon after every declaration, each selector and declaration on its own line, and a blank line between rules.
7. Use meaningful, hyphenated class names
Name classes for what they are, not how they look, and separate words with hyphens: .site-nav or .video-player, not .blue-box or .navbarleft. Avoid ID selectors for styling, as they’re hard to override.
8. Use HTTPS and valid, semantic HTML
Load images, scripts and stylesheets over HTTPS. Use elements for their meaning, such as <nav>, <article> and <button>, and give images useful alt text.
9. Mark to-dos with TODO
Google suggests marking unfinished work with TODO followed by your name, such as <!-- TODO(chandra): add footer links -->, so it’s easy to search for later.
Always validate your code
Check your HTML with the W3C Markup Validation Service and your CSS with the W3C CSS Validator. They catch unclosed tags, typos in properties and other errors that browsers silently ignore.
Let tools do the work
You don’t have to remember every rule:
- Prettier formats HTML and CSS automatically with consistent indentation and spacing.
- Stylelint warns about CSS errors and can enforce rules like lowercase hex colours and alphabetical order.
- Most code editors, including VS Code, can format on save.
Clean code also makes optimisation easier, like our tips to load Bootstrap faster.
Frequently asked questions
Does Google use this style guide for rankings?
No. It’s a coding guide for developers, not an SEO rule. But clean, valid HTML helps browsers and search engines read your pages correctly.
Should I use tabs or spaces?
Google’s guide uses 2 spaces. What matters most is being consistent across your project.
Is alphabetical CSS order required?
No, it’s a recommendation. Some teams group properties by type instead. Pick one approach and use it everywhere.
Get our free weekly email: new tech guides and tools, no spam.
New and updated tech guides, a free tool worth bookmarking and one useful pick, once a week. No spam, unsubscribe anytime.
One email a week. Unsubscribe anytime. See our privacy policy.







I would like to thank you for proving nice information going on ccs style sheet, these tips are good tips for learner.
Thank you for good suggestion on ccs style sheet, these tips are very helpful to developers and designers.
Nice CSS Style. I am a Web Designer. your Tips will help me Very Much. thanks for Sharing.
Thanks but New coders and learners are also using w3schools and they are better.
True. W3Schools is a great resources, and if someone devotes adequate time, they can code well. This guides is a small cheatsheet and created by Google.
Hopefully new developers will quickly move away from w3schools.
https://www.w3fools.com/
Stick with MDN and trustworthy sites like Css-Tricks, Smashing Magazine, A List Apart and QuirksMode instead.
What’s wrong with using the TAB key to create spaces?
I also used to use TABS which indents upto 5 spaces, but if you have deep nesting at several levels, there might be lots of horizontal scrolling involved, or the text may wrap back. 2 spaces as standards seems like a good idea, creating moderate indent.