Skip to main content
Available in Adrop Web SDK 1.2.3 or later.

TL;DR

For most slots, copy this pattern:
This single pattern gives you:
  • Responsive width — the slot fills the device width on any screen
  • Locked heightaspect-ratio derives the height from the width, so no CLS
  • Predictable renderingfixed mode stretches the backfill ad to the container exactly
The two ingredients are backfillMode: fixed and aspect-ratio (inline) matching the registered unit size (320/100, 300/250, 728/90, …).
Prerequisite: this snippet assumes Adrop.observe({ appId: 'YOUR_APP_ID' }) has been called somewhere on the page. While developing, replace YOUR_UNIT_ID with PUBLIC_TEST_UNIT_ID_320_100 to see a live test ad. For SDK install and initialization, see the Banner Ads or CDN guides.

When to Use Which Mode

Both modes are CLS-safe when the container has an inline size intent (aspect-ratio, height, min-height, or max-height). The difference is whether the publisher or the network decides the height.
fixed mode follows the container’s height directly. If the container has no aspect-ratio or height defined, the ad collapses to 0px and becomes invisible — always pair fixed with a height intent.

Container Patterns

Pick the pattern that matches your slot. All three work with both direct and backfill ads. The slot fills the available horizontal width, and aspect-ratio derives the height from the unit’s registered size. Best for mobile-first layouts and content feeds.
Use the aspect-ratio that matches the unit’s registered size. The container’s height is width × (ratio.h / ratio.w), and fixed mode tells the SDK to fill that exact box.
If you need to cap the width, base the cap on your own design (content column, sidebar width, etc.) — not on the registered ad size. Pinning max-width to the registered pixel size shrinks the ad on wider screens and reduces revenue. As long as the ratio is preserved, the backfill ad fills the container at any width.

Pattern B. Fixed pixel height (pixel-precise alignment)

Use this when the slot must align pixel-by-pixel with other content (a docked header, sidebar, sticky footer).

Pattern C. SDK auto-reservation (no size committed)

Use this when you don’t want to commit to a size — the SDK reserves a safe min-height based on the container width to keep CLS low, and the backfill network picks the best inventory match.
This is the default behavior. No data-adrop-backfill-mode attribute needed.

Specifying the Mode

The narrowest scope wins:
Per-slot (declarative)
Per-slot (programmatic)
Publisher-wide default

Size Intent Must Be Inline

The SDK reads only these four inline properties as size intent:
  • height
  • min-height
  • max-height
  • aspect-ratio
If any of them is present inline, the SDK preserves the publisher’s layout and skips auto-reservation.
All other styles — width, padding, margin, color, border, shadow, transition, etc. — can use CSS classes or Tailwind freely. Only those four size-intent properties need to be inline.
The SDK cannot see sizes pinned through CSS classes. In responsive mode, auto-reservation runs in parallel with the class-driven height and may extend the container beyond what you intended.
How to fix (pick one):
  1. Move size intent to inline style (recommended)
  2. Opt into fixed to disable auto-reservation

CLS and Auto-Reservation

What is CLS? Cumulative Layout Shift happens when a late-arriving ad pushes the rest of the content down. A button users were about to tap suddenly moves, causing misclicks. It also affects search ranking and ad revenue. How responsive mode handles it: when the container has no inline size intent, the SDK reserves a safe min-height based on the container width.
  • If the actual ad is larger than the reserved value, the container expands naturally (the jump is just smaller).
  • If the actual ad is smaller, the empty space remains (no jump occurs).
  • Only min-height is set — never max-height — so there is no overflow risk.
If you express height or aspect-ratio inline, the SDK skips auto-reservation entirely — your layout wins.

Auto-Refresh

Once a backfill ad loads successfully, the SDK manages refresh automatically — you don’t need to configure or call anything.
  • Visibility-gated: refresh counts only while the container is at least 50% visible and the page tab is active
  • Bounded: refreshes stop after a fixed maximum count per slot
  • Self-cleaning: when the container is removed from the DOM, refresh is unregistered automatically
Every successful refresh fires an AD_RECEIVED event with format: 'backfill'.

When No Backfill Is Available

If neither a direct ad nor a backfill ad can be served, the SDK emits the AD_BACKFILL_NO_FILL event. Listen for it to hide the slot or render fallback content.
For the full event lifecycle, see the Banner Ads guide.

Upgrading to 1.2.3

The default mode is responsive, so most upgrades are safe with no code change. To freeze the pre-1.2.3 layout, add a single fixed opt-in (globally or per-slot).

Banner Ads (React)

Implement banner ads in React

Banner Ads (CDN)

Implement banner ads via CDN

Reference

BackfillMode type definition