Responsive AdSense ad units: data-ad-format, full-width mobile ads and CSS sizing
Key takeaways
- AdSense display ad units are responsive by default and calculate their size from the width of the parent container and the user's screen.
- data-ad-format defaults to "auto" and can be set to "rectangle", "vertical", "horizontal" or a comma-separated combination, which shapes the ad on desktop only.
- data-full-width-responsive="true" lets the unit expand to the full screen width on mobile in portrait mode more often; "false" stops it, which Google says may reduce earnings.
- Google documents CSS media query changes to set exact sizes per screen width or hide a unit on small screens, and these are acceptable code modifications.
- When you size or hide a responsive unit with CSS, Google says to remove the data-ad-format and data-full-width-responsive lines.

A responsive AdSense display unit sizes itself from the width of its parent container and the user’s screen. Two attributes control it: data-ad-format (default "auto", or a shape such as "horizontal") and data-full-width-responsive (whether it may go full width on mobile). If you need exact sizes per breakpoint, Google documents a CSS media query version of the code, which is an approved modification.
What does the default responsive code look like?
When you create a display ad unit and leave “Responsive” selected, AdSense generates code like this (placeholders used):
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-0000000000000000"
crossorigin="anonymous"></script>
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-0000000000000000"
data-ad-slot="1234567890"
data-ad-format="auto"
data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
Google’s responsive behaviour article lists what this code does:
- Automatic sizing: “We calculate the required size dynamically based on the available space and the size of the user’s display.”
- Orientation changes: if the layout changes when a phone or tablet rotates, AdSense requests and loads a new ad of the right size. If the device rotates back, the original ad is shown again from cache. Google notes that these extra requests “may cause a slight decrease in RPM and CTR metrics” with no negative impact on overall revenue.
- Full-width ads on mobile: units expand to the full screen width when the device is in portrait orientation, “only … when they’re likely to perform well”.
What values can data-ad-format take?
Per How to use responsive ad tag parameters:
| Value | Effect |
|---|---|
"auto" (default) |
Auto-sizing for the available space |
"horizontal" |
General horizontal shape |
"vertical" |
General vertical shape |
"rectangle" |
General rectangular shape |
Combination, e.g. "rectangle, horizontal" |
Any of the listed shapes |
Google labels the shape setting “desktop only”. On mobile the unit still adapts to the container. Other values you will meet in generated code, such as "fluid" for in-feed and in-article units or "autorelaxed" for Multiplex, belong to those unit types; do not paste them into a display unit. The in-article, in-feed and Multiplex guide covers them.
Example, a horizontal unit for a header or below-article slot:
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-0000000000000000"
data-ad-slot="1234567890"
data-ad-format="horizontal"></ins>
What does data-full-width-responsive change?
| Setting | Behaviour on mobile | Google’s note |
|---|---|---|
"true" |
Expands to full screen width more frequently | Recommended, “maximum potential for increased revenue” |
"false" |
Never expands automatically to full width | “you may decrease your potential earnings” |
| Attribute absent | Still expands in some cases, less often than "true" |
Full width means the ad can extend beyond your content column’s padding to the edges of the screen. Set "false" where that would collide with your design, for example inside cards, in grids, or next to a sticky element.
How do I set exact sizes per screen width?
Google’s How to modify your responsive ad code provides a CSS version, explicitly listed as an acceptable modification. Adapted with placeholders:
<style>
.ad_header_1 { width: 320px; height: 100px; }
@media (min-width: 500px) { .ad_header_1 { width: 468px; height: 60px; } }
@media (min-width: 800px) { .ad_header_1 { width: 728px; height: 90px; } }
</style>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-0000000000000000"
crossorigin="anonymous"></script>
<ins class="adsbygoogle ad_header_1"
style="display:block"
data-ad-client="ca-pub-0000000000000000"
data-ad-slot="1234567890"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
Rules from Google’s article:
- Start from a display unit created with “Responsive” selected.
- Give the class a unique name containing only English letters, numbers and underscores, starting with a letter, and use a different name each time you adapt the sample.
- Remove
data-ad-format="auto"anddata-full-width-responsive="true"from the<ins>. - Keep the
<style>block in the page. Google states that “setting the size of the ad unit via CSS in external style sheets is not officially supported.” - Test on several devices and screen widths.
This version is the most predictable for layout stability, because the slot has its final size before the ad arrives. That is the basis of reserving space to prevent CLS.
Expandable width, fixed height
Google also documents a fluid-width banner with a fixed height, set inline:
<ins class="adsbygoogle"
style="display:block;min-width:400px;max-width:970px;width:100%;height:90px"
data-ad-client="ca-pub-0000000000000000"
data-ad-slot="1234567890"></ins>
Can I hide an ad unit on small screens?
Yes, with a media query, and only this way. Google’s example:
<style>
.ad_sidebar_1 { display: block; width: 320px; height: 50px; }
@media (max-width: 400px) { .ad_sidebar_1 { display: none; } }
@media (min-width: 500px) { .ad_sidebar_1 { width: 468px; height: 60px; } }
@media (min-width: 800px) { .ad_sidebar_1 { width: 728px; height: 90px; } }
</style>
<ins class="adsbygoogle ad_sidebar_1"
data-ad-client="ca-pub-0000000000000000"
data-ad-slot="1234567890"></ins>
Google says this makes it so “no ad request is made and no ad is shown” below 400px. Again, remove data-ad-format and data-full-width-responsive.
Hiding is a narrow exception. The code modification policy lists hiding ad units at any time, for example with display:none, among the changes that are not permitted, with responsive ad units as the exception. Hiding with JavaScript after the ad loaded, or hiding units that already served, is outside that exception.
Should I use a fixed-size unit instead?
Google’s Guidelines for fixed-sized display ad units describe the trade-off. Fixed-size units “don’t dynamically change their size or respond to changes in screen orientation”, and “if your site uses responsive design, we recommend that you use a responsive display ad unit instead”. Fixed sizes make sense when you need an exact box for your layout or a regional size that is popular in your market.
Fixed sizes also have hard limits: only one dimension above 450 pixels, a minimum of 120 pixels wide and 50 pixels high, and nothing over 1200 pixels. Units outside these limits do not show at all.
Even a fixed unit can serve a different size. The Ad formats FAQ names two features that cause this: “Similar sized display ads” and “Ad size optimization”, which lets Google optimize the size of units on mobile. Both can be turned off, the latter under Ads > Global settings, with Google’s warning that doing so “may have a negative impact on your ad unit performance”. For most responsive sites, the CSS media query method above gives the control of a fixed size without leaving the responsive unit type.
Why does my responsive unit fail to size?
Google lists the situations where the responsive code cannot calculate a size (responsive behaviour article):
| Situation | What goes wrong | Google’s fix |
|---|---|---|
| Third-party scripts run first and hide ads until the page loads | The ad code cannot measure the slot | Set sizes with CSS media queries |
| Parent container has no explicit width (e.g. a floating element) | No width to calculate from | Set the parent’s size with CSS media queries |
| Parent container has a fixed or limited height | The ad may be taller than the box | Set the parent’s height with media queries instead |
| Mobile device on a poor connection | Some browser reflow while the height is calculated | Expected behaviour |
In the browser console, a slot measured at zero width shows the library message “No slot size for availableWidth=0”. It usually means the <ins> sits in a hidden tab, a collapsed menu, a display:none parent or a flex item that shrank to nothing.
Common mistakes
- Wrapping the unit in a box with
height: 250px; overflow: hidden. Responsive ads can be taller on some devices, and clipping an ad is covering it with content. Usemin-heighton the wrapper instead. - Moving the size CSS to your main stylesheet. It may work, but Google says it is not officially supported. Keep it in a
<style>block next to the unit. - Keeping
data-ad-format="auto"with CSS sizes. Google’s instructions say to delete it when you set exact sizes. - Reusing the same class name for different units. Google asks for a unique name per adapted unit.
- Expecting shapes on mobile.
data-ad-formatshapes are desktop only. - Placing ads too close to buttons and navigation. Responsive sizing can make a unit larger than you expect. Check the ad placement policies on accidental clicks after testing on small screens.
If units stay blank even when sized correctly, the slot may simply be unfilled; unfilled ad slots explains how to detect and style that state.
Frequently asked questions
What does data-ad-format="auto" do?
It enables the auto-sizing behaviour of a responsive display unit: AdSense calculates the ad size from the space available in the parent container and the size of the screen. It is the default value in generated responsive code. You can replace it with "rectangle", "vertical", "horizontal" or a comma-separated combination to suggest a general shape, which applies on desktop only.
Should I set data-full-width-responsive to true or false?
Google recommends "true", saying it makes the unit expand to full screen width on mobile more often and has the maximum revenue potential. Use "false" when a full-width ad would break your layout, for example inside a narrow card or next to a sidebar on tablets. Without the parameter, full-width expansion still happens sometimes, just less often.
Can I give a responsive ad unit a fixed size with CSS?
Yes. Google's "How to modify your responsive ad code" article shows a class on the ins element with width and height set per screen width through media queries in a style block. Remove data-ad-format and data-full-width-responsive when you do this. Google notes that setting the size through external style sheets is not officially supported.
Why is my responsive ad unit not showing?
The most common cause is a parent container without a usable width, such as a floated element or a hidden tab, so AdSense cannot calculate a size. A parent with a fixed or limited height is another. Scripts that hide ads until the page has loaded also prevent the size calculation. Give the container an explicit width or use CSS sizing.
Sources
- About the responsive behavior of display ad units · Google AdSense Help
- How to use responsive ad tag parameters · Google AdSense Help
- How to modify your responsive ad code · Google AdSense Help
- Modifications of AdSense ad code · Google AdSense Help
Related guides
- How to prevent layout shift (CLS) from AdSense ads by reserving slot space
Stop AdSense ads from shifting your layout: reserve slot space with min-height or fixed CSS sizes, handle unfilled slots, and keep Auto ads shifts in check.
- Unfilled AdSense ad slots: reading data-ad-status and handling blank spaces cleanly
Why AdSense slots stay blank, how data-ad-status reports filled, unfilled and unfill-optimized units, and how to hide or replace empty slots within policy.
- In-article, In-feed and Multiplex ads: where each native AdSense format belongs and how to place the code
Where AdSense native formats go and how to code them: In-article ads between paragraphs, In-feed ads inside list loops, and Multiplex grids after articles.
- AdSense ad placement policies: labels, accidental clicks, navigation, pop-ups and floating ads
The AdSense ad placement rules in one place: allowed ad labels, encouraging clicks, ads near navigation, floating boxes, pop-ups, refresh and overlap, with fixes.
- Auto ads vs manual ad units: which one to use, and how to combine them
Auto ads or manual ad units? Compare control, formats, page and area exclusions, and how AdSense combines both on one page without double work.