Ad code implementation

Where to place ad unit code in your HTML

After you've created your ad unit, you need to place two pieces of code on your page:

  • The AdSense code which you paste between the <head> and </head> tags of your site.
  • The ad unit code which you paste between the <body> and </body> tags of your page where you want ads to appear.

It's important that you place both pieces of code correctly otherwise ads might not appear on your site.

WordPress user? Get help with adding AdSense code.

Example HTML page before the AdSense code and ad unit code have been added

<html>
<head>
This is the head of your page.
<title>Example HTML page</title>
</head>
<body>
This is the body of your page.
</body>
</html>

Example HTML page with the AdSense code in the head and the ad unit code in the body

<html>
<head>
<script data-ad-client="ca-pub-1234567890123456" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
This is the head of your page
<title>Example HTML page</title>
</head>
<body>
This is the body of your page.
<ins class="adsbygoogle"></ins>
</body>
</html>
Note: This is sample code only, please don't use it in your own site's HTML.

Positioning the ads on your site with HTML

Just like the other elements of your site (images, paragraphs, etc.), you can change the position of your Google ads by using HTML tags (<div>, <table>, etc.). For example, if you surround your ad unit code with the HTML tags <div align="center"> and </div>, your ads will appear in the center of your page.

<html>
<head>
<script data-ad-client="ca-pub-1234567890123456" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
This is the head of your page
<title>Example HTML page</title>
</head>
<body>
This is the body of your page.
<div align="center">
<ins class="adsbygoogle"></ins>
</div>
</body>
</html>

Note: This is sample code only, please don't use it in your own site's HTML.
Was this helpful?
How can we improve it?