Please note that the JavaScript inclusion must use the HTTPS protocol. You can include the file at any point in your document but for performance reasons you should consider deferring the parsing of JavaScript files. By deferring parsing of unneeded JavaScript until it needs to be executed, you can reduce the initial load time of your page which can improve performance. You can find more information on page speed optimisation.

Now that you have include the Plus One JavaScript file, it is now time to add the corresponding HTML5 placeholder. You can add the following code anywhere in your document, but you must ensure it the class is set to “g-plusone” else it won’t work.

<div class="g-plusone" data-size="medium" data-count="true"></div>

You can customize the look and feel of Google +1 button by including attributes prefixed with data-, for example if you want to customize it to have a small size you need the following:

<div class="g-plusone" data-size="small" data-count="true"></div>

Notice the “count” attribute is a boolean, you can set it to “true” or “false” to show/hide it. The following chart indicates the available types/sizes of +1 one button.

On a final note, Google will use the href value that you have passed. However, if the href attribute isn’t set, Google will next look for the rel="canonical" tag on the page. If that isn’t found, Google will use the document.location.href.

UPDATE 1:

My colleague Dom Calisto has just pointed out that Google’s code doesn’t work in some browsers and I had forgotten to call the API. Please use the following code:

UPDATE 2:

Here is a better way of implementing Google +1. I am using jQuery to trigger the function when document is ready, but you can go ahead and remove the jQuery if you are calling the API at the bottom of your document. The following code also allows you to customize Google +1 using lean and valid HTML5 code. Note, I am not using rel=canonical tag in this example, this is purely because I want the code to validate. You could always declare canonical but then the document wouldn’t validate. Check out the Google +1 button demo.