How can I close a modal in Webflow when clicking outside of it, without closing the modal when clicking on the modal itself?

TL;DR
  • Set up a modal structure with a modal overlay and content area.
  • Select the modal overlay, create a new click interaction in Webflow, and implement a "hide modal" animation to set the display to none.
  • Ensure the modal content does not have interactions that close the modal, and test the settings to ensure only the overlay click closes the modal.

Closing a modal in Webflow by clicking outside of it requires some interaction setup. Follow these steps to achieve this:

1. Setup Your Modal Structure

  • Ensure your modal has a specific structure, typically with a modal overlay that acts as the clickable background and a modal content area.

2. Create a Click Interaction on the Modal Overlay

  • Select the modal overlay element in the Webflow Designer.
  • Go to the Interactions panel and create a new click interaction.

  

3. Hide Modal Interaction

  • In the interaction settings, create a “hide modal” animation:
  • 1st Click: Set the display property of the modal (overlay) and content to none after a specified delay if desired.
  • 2nd Click (optional): If you want to toggle open with the same click, implement the show modal logic.

4. Prevent Modal Content Interaction

  • Select the modal content area.
  • Ensure no new interactions are added to the content itself that close the modal.

5. Interaction Finalization

  • Save the interaction and test the click settings to ensure clicking on the content does not close the modal, but clicking on the overlay does.

Summary

By applying a click interaction to the modal overlay to hide the modal, and ensuring the content area lacks such an interaction, you can close a modal upon clicking outside without affecting interactions when clicking on the modal itself. Adjust styling to ensure visual clarity for your users.

Rate this answer

Other Webflow Questions