How can I create a modal for an image in Webflow using the provided HTML markup?

TL;DR
  • Create a thumbnail image and a hidden modal with an enlarged image and close button using Div Blocks.  
  • Style the modal with fixed positioning, center alignment, and overlay background.  
  • Use interactions to show the modal (fade-in) when the thumbnail is clicked and hide it (fade-out) when the close button is clicked.

To create a modal for an image in Webflow, you need to use Webflow's Designer to structure elements and apply simple interactions — no raw HTML is required or recommended. Below are step-by-step instructions to create an image modal using Webflow's native tools.

1. Add Your Image and Modal Elements

  • Drag an Image Element into your canvas for the thumbnail.
  • Create a Div Block that will serve as the modal overlay. Name it something like Image Modal.
  • Inside the modal div, place:
  • Div Block for centering (optional).
  • Another Image Element that will display the enlarged image.
  • Close Button (Text or Icon) to close the modal.

2. Apply Initial Styles

  • Set the Image Modal (overlay) to Display: None.
  • Add the following styles to the Image Modal:
  • Position: Fixed
  • Top/Bottom/Left/Right: 0
  • Z-index: High value (e.g., 9999)
  • Background: rgba(0,0,0,0.6) for dark overlay
  • Justify/Align: Center (Flexbox) to center the image
  • Style the larger image and close button as needed.

3. Add Interactions to Open the Modal

  • Select your thumbnail image, go to the Interactions (lightning icon) panel.
  • Add a Mouse Click (Tap) trigger.
  • Choose Start an Animation, then click +New Timed Animation and name it (e.g., "Open Modal").
  • Add an animation step:
  • Element: your modal
  • Action: Display → Block (instant)
  • Then, Opacity → 0% → 100% for fade-in effect

4. Add Interactions to Close the Modal

  • Select the Close button inside your modal.
  • Add another Mouse Click (Tap) trigger.
  • Choose Start an Animation and name it (e.g., "Close Modal").
  • Add animation steps:
  • Opacity → 100% → 0% (fade-out)
  • Display → None (after fade finishes)

5. (Optional) Swap the Modal Image Source Dynamically

If you're using a single modal for multiple images:

  • Use custom code and embed elements with data-image attributes or JavaScript inside Webflow’s Page Settings > Before </body> tag.
  • However, if you only have one modal per image, this can be static and interaction-based only.

Summary

To create an image modal in Webflow, build your modal using Div Blocks and Image Elements, assign display and position styles, then use interactions to control showing and hiding the modal on image click. Avoid using raw HTML markup — Webflow’s Designer is optimized to build this visually with full control.

Rate this answer

Other Webflow Questions