To create an image modal in Webflow using provided HTML markup, you’ll need to configure elements and interactions in the Designer to open and close the modal.
1. Add the Base Elements
- Add your image to the canvas that will trigger the modal.
- Place a new Div Block somewhere on the page and give it a class like
modal-wrapper
. - Inside
modal-wrapper
, add: - A Div Block with the class
modal-content
. - An Image element, which will display the enlarged image.
- A Close icon (e.g., a text block with an "X" or an SVG/icon).
2. Style the Modal Elements
- modal-wrapper:
- Set position to
fixed
, top/right/bottom/left to 0
. - Set display to
none
or hidden initially. - Add a semi-transparent background color (e.g., rgba(0,0,0,0.7)).
- Set z-index high enough to overlay content.
- modal-content:
- Set to position: relative, margin: auto, and optionally define max-width or max-height.
- Close icon:
- Set position: absolute, top-right inside
modal-content
.
3. Set Up the Interaction to Open the Modal
- Select the thumbnail image (the trigger).
- Go to the Interactions panel, click + to create a new mouse click (tap) interaction.
- Set Action to Show/Hide and choose your
modal-wrapper
element. - Under Effects:
- Choose Display: Block.
- Optionally add a fade-in animation (adjusting opacity and scale).
4. Set Up the Interaction to Close the Modal
- Select the "X" close button inside
modal-wrapper
. - Add a click interaction to this element.
- Choose Hide/Show → Display: None for
modal-wrapper
. - Optionally animate the opacity for a fade-out effect.
5. Optional: Dynamic Image Source
- If creating dynamic modals for CMS content:
- Set the modal image's
src
dynamically using CMS bindings or use custom code to update the image source when the thumbnail is clicked.
Summary
To create an image modal in Webflow, build a hidden modal wrapper with the necessary image and close button, then use interactions to control its visibility. Display the modal on thumbnail click and hide it with a close action.