How to center Google AdSense ads
It took me awhile to figure out how to center Google AdSense ads. Searches showed that many other people were running into the same issue, so I thought I would share my method for centering.
At first I tried things like margin:auto, center and padding in a <div> wrapped around the ad, but nothing seemed to work. The reason for this is the AdSense box is absolutely positioned. The easy fix for this is to create a CSS class or inline style as shown below.
CSS class
.adSenseCenter { position:relative; width:120px; margin:auto; }
Container <div>
<div class="adSenseCenter"> adSense code goes here </div>
Or quick and dirty inlines style.
<div style="position:relative; width:120px; margin:auto;"> adSense code goes here </div>
Don’t forget that the width of the <div> must equal the width of the adSense ad. Now you can center your ads.
Keith December 11, 2009 at 9:36 am
I realize this post is over a year old, but THANK YOU so much for posting it. I’ve been trying to center my adsense header for quite some time and just become more frustrated and more frustrated. You advice worked perfectly!
chris March 21, 2010 at 11:52 pm
works a charm, but would possible to move the ad down a little.
eg: in the center and also moved down a little?
my google ad is againest the very top and i would like to move it down a bit still centered.
thanks.
Ian Hoar March 22, 2010 at 12:07 am
Chris you can probably position it relatively or use a margin. Something like margin:20px auto 0 auto;
Matt October 12, 2010 at 4:23 am
Thanks very much for this. First search hit in Google and centred my ads correctly. Used in conjunction with advert manager plugin for wordpress.
Antonio November 1, 2010 at 7:18 pm
Great!!!! Thanks a lot Ian, after almost 2 hours Googling and trying many many different ways of centering and moving my adsense with no positive results, I found your site and man it just made my day after so much frustration.
Greetings form México
Simon September 21, 2011 at 1:13 pm
Thank you Ian, because of you and you only did I manage to center my adsense 🙂
Enjoy your day.
Greetings from South Africa
DateSphere - Chris October 18, 2011 at 4:04 pm
Thanks so much for posting this, just implemented on my site and it worked great!
Tall Curly Biscuit October 24, 2011 at 9:29 pm
Thank you! Nothing ever works the first time, except this!
Joseph November 22, 2011 at 12:26 pm
This worked like a charm! On both FF7 and IE7. Thank you!
Mario February 5, 2012 at 7:45 am
This worked perfectly!! Thank you very much!!
Best regards
Ramon Fincken July 18, 2012 at 9:35 am
Excellent! This is the only working tutorial I found 🙂
Haze October 1, 2012 at 2:05 pm
Searched for aaaages and eventually found you! -thank you!!!!
Graham J Smith November 1, 2012 at 7:54 am
Brilliant! I saw a post back there thanking you for this gem in Oct 2009 when your post was a year old. Now its four years old – and it’s kept it’s value. Not much doing that nowadays. I was so glad to find this. Thankyou for posting this timeless gem.
becky January 5, 2013 at 10:44 pm
love it! worked like a charm. thank you thank you for sharing!
Jukkis February 4, 2013 at 1:25 pm
Thank you very much 🙂 I tried lots of things before i found this post. Thanks again.
Nen February 2, 2016 at 7:00 am
Thank you for that – solved a long standing problem 🙂
Gordon Warden February 18, 2016 at 7:31 am
Simple solution, using wordpress, open a new page, paste your adsense code into the text section, “select all” and then centre it. Then copy and paste to whereever you want your ad to appear.
I have just done this on my website Brittany.pro
Hope this is helpful
Gordon