To adapt this sample code for your own site:
- Create a display ad unit in your AdSense account, making sure you leave Responsiveselected in the "Ad size" section. Note down the following information from your responsive ad code:
- Your publisher ID, for example, ca-pub-1234567891234567
- Your ad unit's ID (data-ad-slot), for example, 1234567890.
- In the sample code:
- Replace all instances of example_responsive_1 with a unique name, e.g., Home_Page, front_page_123, etc.
Notes:
- Your unique name must only contain English letters (A-Z), numbers, and underscores, and the first character must be an English letter.
- You must use a different unique name each time that you adapt this sample code.
- Replace ca-pub-XXXXXXX11XXX9 with your own publisher ID.
- Replace 8XXXXX1 with your own ad unit's ID.
- Decide on the sizes you want your ad unit to take per screen width:
- If you're happy with the existing ad unit sizes in the sample code, then you don't need to make any additional changes.
- If you want to set different ad unit sizes per screen width, then, in the sample code:
- Replace 320px and 100px with the width and height of the ad unit you want to use for screen widths up to 500px.
- Replace 468px and 60px with the width and height of the ad unit you want to use for screen widths between 500px and 799px.
- Replace 728px and 90px with the width and height of the ad unit you want to use for screen widths of 800px and wider.
- Copy and paste your modified ad code into the HTML source code of the page where you'd like the ads to appear.
Note: After you’ve placed your ad code, we recommend that you test your ads on different devices and screens to make sure that the responsive behavior is working correctly.
Specify an expandable width and a fixed height
You may modify your responsive ad code to specify an expandable width and a fixed height for your ad unit via CSS. The following example shows you how to make these modifications:
Expandable width with fixed height example
This example shows you how to modify your responsive ad code to specify a fixed height of 90px and a variable width from min-width 400px to max-width 970px: