|Description||Displays elements in a full-viewport “lightbox” modal.|
|Examples||See AMP By Example's amp-lightbox sample.|
- Using amp-lightbox in AMPHTML ads
amp-lightbox component defines child elements that display in a full-viewport overlay/modal. When the user taps or clicks an element (e.g., a button), the
amp-lightbox ID referenced in the clicked element's
on attribute triggers the lightbox to take up the full viewport and displays the child elements of the
Pressing the escape key on the keyboard closes the lightbox. Alternatively, setting the
on attribute on one or more elements within the lightbox and setting its method to
close closes the lightbox when the element is tapped or clicked.
Defines the style of animation for opening the lightbox. By default, this will
be set to
fade-in. Valid values are
fly-in-* animation presets modify the
transform property of the
amp-lightbox element. Do not rely on transforming the
directly. If you need to apply a transform, set it on a nested element instead.
close-button (required on AMPHTML ads)
Renders a close button header at the top of the lightbox. This attribute is only required and valid for use with AMPHTML Ads.
A unique identifer for the lightbox.
Must be set to
scrollable attribute is present, the content of the lightbox can scroll when overflowing the height of the lightbox.
scrollable attribute is not allowed when using
<amp-lightbox> inside an AMPHTML ad. For details, read the Using amp-lightbox in AMPHTML ads section.
You can style the
amp-lightbox with standard CSS.
amp-lightbox exposes the following actions you can use AMP on-syntax to trigger:
||Opens the lightbox.|
||Closes the lightbox.|
There are some differences between using
amp-lightbox in normal AMP documents vs. ads written in AMPHTML:
For AMPHTML ads, the
close-button attribute is required. This attribute causes a header to render at the top of your lightbox. The header contains a close button and a label that displays "Ad". Requirement of this header is needed to:
- Set a consistent and predictable user experience for AMPHTML ads.
- Ensure that an exit point for the lightbox always exists, otherwise the creative could effectlively hijack the host document content via a lightbox.
close-button attribute is required and only allowed in AMPHTML ads. In regular AMP documents, you can render a close button wherever you need it as part of the
Scrollable lightboxes are disallowed
For AMPHTML ads, scrollable lightboxes are not allowed.
When you use
<amp-lightbox> in AMPHTML ads, the background of your
<body> element becomes transparent because the AMP runtime resizes and realigns your creative's content before the lightbox is expanded. This is done to prevent a visual "jump" of the creative while the lightbox opens. If your creative needs a background, set it on an intermediate container (like a full-size
<div>) instead of the
When the AMPHTML ad is running in a third-party environment (for example, in a non-AMP document), the creative is centered relative to the viewport and is then expanded. This is because third-party iframes need to rely on a postMessage API to enable features like frame resizing, which is asynchronous, so centering the creative first allows a smooth transition without visual jumps.
Examples of transitions in lightbox for AMPHTML ads
In the examples below, we demonstrate how the transition looks for an AMPHTML ad that has the
animate-in="fly-in-bottom" attribute set on the lightbox element for an AMPHTML ad in a friendly iframe, and an AMPHTML ad in a third-party iframe.
On friendly iframes (e.g., coming from an AMP cache)
On third-party iframes (e.g., outside the AMP cache)
See amp-lightbox rules in the AMP validator specification.