3

TLDR;

Does Google care how code is formatted?

Background

I work in an agency. One developer is trying to convince the other to put line-breaks between rules in his css file:

.class {
    width:100%;
    height:auto;
}

as opposed to inline: .class { width:100%; height:auto; }

The argument is that it reduces the file-size, to which the counter-argument is "we're minifying the css" afterward.

The last argument is "Google cares about how code is formatted" and presented the following link https://google.github.io/styleguide/htmlcssguide.xml

We pointed out that one of the last points at the bottom of the page is that css rules must have line breaks in them:

Always put a blank line (two line breaks) between rules.

html {
  background: #fff;
}

body {
  margin: auto;
  width: 50%;
}

Even with his own argument blown out of the water he is still adamant that Google cares about css, html etc being minified and inline.

Which leads to my question (looking for an authoritative answer - links to official Google website required) - Does Google care how code is formatted?

My personal answer is "No", otherwise Google wouldn't be telling us minifying our code to reduce load time on mobile devices etc.

6
  • 2
    If you are minifying the CSS after it is developed, Google will only ever see the minified version. They way that the code is formatted for your developers can only ever by an in-house issue at that point. Commented Feb 24, 2016 at 16:29
  • Possibly pedantic but you never can tell... "One developer is trying to convince the other to put line-breaks between rules in his css file, as opposed to inline. The argument is that it reduces the file-size" - you seem to have your "argument logic" reversed?
    – MrWhite
    Commented Feb 24, 2016 at 17:20
  • The second developer's argument is that it reduces file size. Commented Feb 24, 2016 at 17:29
  • Even if the human-readable file should be somewhat larger, it is well possible that the zipped (i.e., Transfer-encoding: gzip) version is not larger, especially if the structuring is consistent (sach as always two newlines between rules) Commented Feb 24, 2016 at 18:35
  • Google the company? Yes. Google the search engine? No.
    – Ajedi32
    Commented Feb 24, 2016 at 20:22

2 Answers 2

8

That whole article is about making code readable for humans and has nothing to do with SEO.

Google does not care about formatting. Google only cares about content. Anything that helps outline that content, such as proper headings to show them where a new section begins and lists, will help them figure out what your content is about and where it begins and ends.

Every company and every person has their own style of writing code. Google does not dictate or suggest you change that but tries to give what they consider best practices or good ideas.

take a few minutes to look at the code around you and determine its style. If they use spaces around all their arithmetic operators, you should too.

You are free to ignore them or accept them as you wish.

3
  • It will impact on your SEO because your load time will be affected from this, if you put the comments and the line breaks together it may exceed 8000 rows which is a lot, also you don't build whole website with just 1 CSS file so it will be problem with all CSS files.
    – knif3r
    Commented Feb 24, 2016 at 16:41
  • @knif3r Yes, what you say is true, but he's referencing what was said in the article about formatting, and the question is about formatting affecting SEO, so my answer addresses that. Gzipping and minifying removes your concerns about line breaks and comments.
    – Rob
    Commented Feb 24, 2016 at 20:35
  • I see, I haven't read the article, sorry.
    – knif3r
    Commented Feb 24, 2016 at 20:54
4

Google will always care about your load time, because it is one of the most important user experience definitive.

According to Akamai research, 47% of the users expect the website to load in 2 seconds, and 57% of the users will leave the page if it doesn't load in 3 seconds.

!Google crawler will cancel the page indexing either if the page doesn't load in 3 seconds!

“A search result for a resource having a short load time relative to resources having longer load times can be promoted in a presentation order, and search results for the resources having longer load times can be demoted.”

It's a good practice to have 2 CSS files, but only 1 active, basically you create your CSS file human readable after your project is completed you backup your CSS on your desktop or a folder for this purpose, leaving the copy aside you should minify the CSS which is still on the website and leave it minified so it can be served faster, and this part isn't my favourite but for every update of the css you are making in future you need to add the changes to both CSS files OR you need to backup the backup and minify the original again.

Your co-worker is both wrong and right about it, if you want to orientate better in your code it's good to have line breaks between the rules, but it will take more time for the code to be served, because the bigger the code is, the bigger problems you have, which is really bad.

3
  • 1
    No, the co-worker is wrong, because the code in question is never made public. Google sees the minified version. Commented Feb 25, 2016 at 4:49
  • As I said it is good to have minified css and js scripts live on your website, but have backup with human readable well formatted code out of your website directory so you can edit it better, and deliver minified version for speed, please read the last paragraph of my answe, thank you.
    – knif3r
    Commented Feb 25, 2016 at 8:33
  • I agree google does care about the load time , the smaller the file size the faster the load time. Its good to even use sass because it requires less code for the style sheet but, does the same thing. Commented Feb 25, 2016 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.