Ad code implementation

How to modify your responsive AMP ad code

If you find that our responsive AMP ad code doesn't do everything that you need, you may modify your ad code to better meet the requirements of your site. The following examples show you how to correctly make these modifications.

Example 1: AMP ad with variable width and fixed height

This example shows you how to create an AMP ad unit with a variable width and fixed height (100 px). We recommend that you leave the width as responsive so it fits naturally with the rest of your page layout.

To create this AMP ad unit, replace the data-ad-client and data-ad-slot values in the following code with your own publisher ID and ad unit ID:

<amp-ad
   layout="fixed-height"
   height=100
   type="adsense"
   data-ad-client='ca-pub-1234567891234567"
   data-ad-slot='1234567890'>
</amp-ad>

Example 2: AMP ad with fixed width and height

This example shows you how to create an AMP ad unit with a fixed width (300 px) and a fixed height (250 px).

To create this AMP ad unit, replace the data-ad-client and data-ad-slot values in the following code with your own publisher ID and ad unit ID:

<amp-ad
   layout="fixed"
   width=300
   height=250
   type="adsense"
   data-ad-client='ca-pub-1234567891234567"
   data-ad-slot='1234567890'>
</amp-ad>
Even with this flexibility, please remember to always follow our ad placement policies. Bear in mind that only limited modifications to your code are permitted by our programme policies.
Was this article helpful?
How can we improve it?