Skip Navigation

Styling Google

Please note that since this article was written, the content Google adds to a page has changed a great deal and the details of this post should now be considered outdated, although the principle remains sound.

Google's search results usually have, just underneath them, a link that says "Cached". This links to a copy of the web page listed - a snapshot taken the last time Googlebot visited the page.

In many ways these snapshots are extremely useful, especially because when you view them the keywords you searched for are highlighted within the page you are viewing.

Because of this, more and more people are using the "Cached" link to view web pages, and this is a problem. It reduces page views, makes it harder for you to track usage of your site, and can even hurt revenue on advertising-based websites. Pages styled using CSS viewed through the cache often look wrong as well, due to the code added to the top of the page.

There are ways around this problem. One is to add a piec of JavaScript to your site to redirect people if they are viewing the cache. Another is to prevent Google from making the cache available, using this META tag:

  1. <meta name="robots" content="noarchive">

These methods will both prevent people from viewing your pages in the Google cache. However, if you want to continue to allow people to view your pages in the Google cache, you might consider adding a little style to the listing while you are at it.

Design is fast moving away from tables, and more and more people are using CSS for style. Google, though, carefully adds a completely invalid piece of completely unnecessary table-based code to the top of every cached copy it serves:

  1. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  2. <BASE HREF="http://www.juno.co.uk/"><table border=1 width=100%><tr><td><table border=1 bgcolor=#ffffff cellpadding=10 cellspacing=0 width=100% color=#ffffff><tr><td><font face=arial,sans-serif color=black size=-1>This is <b><font color=#0039b6>G</font> <font color=#c41200>o</font> <font color=#f3c518>o</font> <font color=#0039b6>g</font> <font color=#30a72f>l</font> <font color=#c41200>e</font></b>'s <a href="http://www.google.com/help/features.html#cached"><font color=blue>cache</font></a> of <A HREF="http://www.juno.co.uk/"><font color=blue>http://www.juno.co.uk/</font></a>.<br>
  3. <b><font color=#0039b6>G</font> <font color=#c41200>o</font> <font color=#f3c518>o</font> <font color=#0039b6>g</font> <font color=#30a72f>l</font> <font color=#c41200>e</font></b>'s cache is the snapshot that we took of the page as we crawled the web.<br>
  4. The page may have changed since that time. Click here for the <A HREF="http://www.juno.co.uk/"><font color=blue>current page</font></a> without highlighting.<br>
  5. This cached page may reference images which are no longer available. Click here for the <A HREF="http://www.google.co.uk/search?q=cache:pYNkmJTkSQMJ:www.juno.co.uk/+juno&hl=en&lr=&ie=UTF-8&strip=1"><font color=blue>cached text</font></a> only.<br>To link to or bookmark this page, use the following url: <code>http://www.google.com/search?q=cache:pYNkmJTkSQMJ:www.juno.co.uk/+juno&hl=en</code></font><br><br><center><font size=-2><i>Google is not affiliated with the authors of this page nor responsible for its content.</i></font></center></td></tr>
  6. <tr><td>
  7. <table border=0 cellpadding=0 cellspacing=0><tr><td><font face=arial,sans-serif color=black size=-1>These search terms have been highlighted: </font></td><td bgcolor=#ffff66><B><font face=arial,sans-serif color=black size=-1>juno </font></B></td></tr></table>
  8. </td></tr></table></td></tr></table>
  9. <hr>

For the record, it could just as easily serve valid, semantically correct code and achieve virtually the same effect. It could also (indeed, should) serve that code after the body tag, so as not to break sites served through the cache. It could even go as far as to spend a second identifying the language of the page and serve valid code. An example of code they could use (removing the colouring from the word Google along the way):

  1. <div style="width:100%;border:0;margin:0;padding:1em;border-bottom:1px solid #000;color:#000;">
  2. This is Google's <a href="http://www.google.com/help/features.html#cached">cache</a> of <a href="http://www.addedbytes.com/">http://www.addedbytes.com/</a>.<br />
  3. Google's cache is the snapshot that we took of the page as we crawled the web.<br />
  4. The page may have changed since that time. Click here for the <a href="http://www.addedbytes.com/">current page</a> without highlighting.<br />
  5. This cached page may reference images which are no longer available. Click here for the <a href="http://www.google.co.uk/search?q=cache:X3GuszbKqvwJ:www.addedbytes.com/+addedbytes&hl=en&lr=&ie=UTF-8&strip=1">cached text</a> only.<br />
  6. To link to or bookmark this page, use the following url: <code>http://www.google.com/search?q=cache:X3GuszbKqvwJ:www.addedbytes.com/+addedbytes&hl=en</code><br />
  7. <div style="margin:1em;font-style:italic;text-align:center;">Google is not affiliated with the authors of this page nor responsible for its content.</div>
  8. <div style="">These search terms have been highlighted:
  9. <span style="background:#ff6;font-weight:bold;">addedbytes</span>
  10. </div>
  11. </div>

The chances of Google going down this route are slim. Perhaps sooner or later they will move to valid code, properly styled, but it is unlikely as it has little bearing on their bottom line. What it means for those of us that wish to allow Google to keep serving cached copies of our pages is that those copies appear broken. Ideally, we would prefer them to not appear broken - we want our visitors to keep using our sites, perhaps even to buy something.

However, all is not lost. Few designers who stick to modern principles use tables or hr tags for layout. For this reason, and as long as you are careful, you can easily add style to the content added to the top of a page by Google. A sample of one possible style is here:

  1. <style type="text/css">
  2.  
  3. /* Nice divider. */
  4. hr {
  5. border: none;
  6. border-top: 1px dotted #000;
  7. height: 1px;
  8. margin: 0;
  9. padding: 0;
  10. font-size: 1px;
  11. background: #fff;
  12. }
  13.  
  14. /* No borders. */
  15. table {
  16. border: none;
  17. border-collapse: collapse;
  18. margin: 0;
  19. padding: 0;
  20. }
  21.  
  22. /* Nice text. */
  23. table font, table code {
  24. font-size: 0.9em;
  25. font-weight: normal;
  26. font-family: verdana;
  27. }
  28.  
  29. /* Makes links look and behave the same as the rest of the document. */
  30. table a font {
  31. color: inherit;
  32. }
  33.  
  34. /* Re-adds bold. */
  35. table b font {
  36. font-weight: bold;
  37. }
  38.  
  39. </style>

You could add the above to the HTML of your pages, or to an external syle sheet. It will affect all tables and <hr> tags, but this can be worked around easily enough through the use of nesting, classes or ids.

This process could be made even easier by Google. If they were to add a simple "id" attribute to their table, eg "<table id="google-cache-top-bar">" (and remove the <hr> tag altogether) we would find it much easier to style the cache notice.

Please note that since this article was written, the content Google adds to a page has changed a great deal and the details of this post should now be considered outdated, although the principle remains sound.

8 comments

KosherJava
United States #1: September 9, 2004
I tried a different approach on my site a while ago and just set display: none for tables. Users now see my page without seeing the google stuff at all.
This assumes you have no tables on your page.
James Sorbet
United Kingdom #2: September 16, 2004
I wouldn't switch away from tables just yet, for the sake of backwards compatibility, it's not a good idea. Older browsers will be lost if there's no positioning at all in the HTML. A well structured page created from valid HTML tables and a stylesheet can still look good in an older browser. Also, CSS positioning just isn't ready for the primetime yet. More often than not it produces rendering problems. Resize the window for this site if you want to see what I mean reduce the width and you'll see the navigation menu disappear at a certain point. This renders the site useless on a small resolution screen, perhaps a PDA or a cellphone. Tables provide the best level of compatibility at this moment.

I had a look at the source of your code. You're using META-EQUIV tags which is quaint. You appear to be trying to set the content type of the page twice, once as "text/html" and then a second time as "text/css".

This is quite amusing as neither of them are actually correct. You are using XHTML1.1 so the document is not html, and it's certainly not css. it's an XML document so the content-type should be "application/xhtml+xml". By not setting this, web browsers aren't actually reading it as XML at all, they're rendering it as HTML which defeats the object!

I'd also avoid using META-EQUIV tags completely. Not all browsers support them. If you need to add or modify a server header, do it on the web server, not in the document.
Hi James,

Thanks for the feedback. One thing at a time ...

Feel free not to switch from tables. That's your choice entirely. CSS layouts can work very badly, if badly done. A well-created HTML and CSS page should degrade well with older browsers.

"This renders the site useless on a small resolution screen, perhaps a PDA or a cellphone." - That would be a problem, if cellphones displayed this site like this. They usually don't though - most reformat pages.

The design for this site isn't perfect. The "Search" header in the nav bar, for example, is broken. It's a work in progress. Now I'm happy with the backend, I'm starting work on a decent front end. Things like content types and so on will be fixed in due course.

The second of the http-equiv tags refers to the style type, and is correct. I agree about the use of http-equiv, and normally do not use it. However, for a hobby site being developed in a limited time, they did the job. They'll be replaced in the new design.

I am aware that XHTML docs should be served as "application/xhtml+xml" according to the specs. However, IE can't handle this type of document. The specs state that "text/html" is fine for HTML-compatible XHTML, which this is. In the next version of the site, I will probably serve correct types to those browsers that can handle it, but am not all that bothered while support is so poor for properly-declared content types.
James Sorbet
United Kingdom #4: September 16, 2004
The W3C site has a cool trick for getting IE to render the XHTML properly. To use it, one needs to use the ContentType of "application/xml"

Start the document with the following...

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="xhtml.xsl"?>

Where xhtml.xsl is a file withe the following content...

<stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform">
<template match="/">
<copy-of select="."/>
</template>
</stylesheet>

It's a nice trick and it all helps in the ongoing effort to conform to the guidelines.
I would hate it if people styled the Google cache information box, leaving an id="" like you said. It would make searching completeley inconsistent and inherently more awkward.
 United Kingdom #6: August 12, 2006
Nice advice dude :)

good to know people in the locality think the same way as myself.

I've also had some major problems with a host causing me a lot of downtime which can make google's cache usefull the only trouble is if like you say the page is destroyed by ugly "google was here" type code why would any user stay put !!!

cya around :)
 United Kingdom #7: August 12, 2006
just one other point id like to make is that most html these days is written on the server by the server at run time meaning weather u use tables or not could be up to your server should you decide that as option.

Compatability can be easily coded by determining the browser type and version and code can be written that works better for that client however there has to be a limit between the perfectly coded site and the time spent getting eventuality sorted so having a good idea of your target audience is also a handy thing to bear in mind.
This is a nice trick indeed. Some of the pages i have created over the last years need a little twinking and i will definately be making the sites better on the eye from a cached point of view once i do this.

Small details make the difference in the end ;)

Post Your Comment

· Comments with keywords instead of a name have their URLs removed.
· Your email address will not be displayed or shared.
· "Remember Me" is disabled - caching is on due to high server load.

Live Comment Preview

 #9: 1 minute ago