Thank you!

  • websites



The amp-lightbox component allows for a "lightbox" or similar experience - where upon user interaction a component expands to fill the viewport, until it is closed again by the user.


Import the amp-lightbox component in the header

<script async custom-element="amp-lightbox" src=""></script>

You can combine the lightbox component with amp-bind.

<script async custom-element="amp-bind" src=""></script>

Basic usage

The amp-lightbox component defines the child elements that will be displayed in a full-viewport overlay. To close the lightbox via click or tap use the on attribute on one or more elements inside the lightbox. In this example the user can click anywhere in the lightbox to close it.

The lighbox is shown when the user taps or clicks on an element with on attribute that targets the id of an amp-lightbox element.

<amp-lightbox id="my-lightbox" layout="nodisplay">
  <div class="lightbox" on="tap:my-lightbox.close" role="button" tabindex="0">
    <h1>Hello World!</h1>
<button on="tap:my-lightbox">
  Open lightbox

For showing images in a lightbox, AMP also features the amp-image-lightbox component, which doesn't need the image to specified twice.

Combination with amp-bind

amp-lightbox can be opened as a result of amp-bind evaluations by binding a boolean value to the open attribute. Note that we're also listening to the lightboxClose event to reset the state of the variable.

<amp-lightbox id="my-bindable-lightbox" [open]="showLightbox" layout="nodisplay" on="lightboxClose:AMP.setState({showLightbox: false})">
  <div class="lightbox" role="button" tabindex="0" on="tap:my-bindable-lightbox.close">
    <h1>Hello World!</h1>
<button on="tap:AMP.setState({showLightbox: true})">
  Open lightbox
Besoin de plus amples explications ?

Si les explications de cette page ne répondent pas à vos questions, n'hésitez pas à contacter d'autres utilisateurs d'AMP pour discuter de votre cas d'utilisation spécifique.

Se rendre sur Stack Overflow
Une fonctionnalité n'a pas encore été expliquée ?

Le projet AMP encourage fortement votre participation et vos contributions ! Nous espérons que vous deviendrez un membre régulier de notre communauté open source, mais nous serons également ravis de recevoir des contributions ponctuelles concernant les questions qui vous intéressent particulièrement.

Modifier l'exemple sur GitHub