Ian Hoar – Passion for Technology – Geeking Out - Technology, Web, Toys, Games, Design, Entertainment, Gadgets, & Geeking Out

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.

3 Comments to “How to center Google AdSense ads”

  • Keith

    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

    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 | |

    Chris you can probably position it relatively or use a margin. Something like margin:20px auto 0 auto;

Responses:

Your comments are important, join the conversation