How can I make my iframe clickable in Webflow?

Published on
September 22, 2023

To make an iframe clickable in Webflow, you can use a combination of CSS and JavaScript. Here's a step-by-step guide on how to do it:

  1. Add an HTML embed element: Drag and drop an HTML embed element onto your Webflow page where you want to display the iframe.

  2. Set the dimensions of the HTML embed: Adjust the width and height of the HTML embed element to match the size of your iframe.

  3. Insert the iframe code: Inside the HTML embed element, insert the code for your iframe.

  4. Apply CSS to the HTML embed: Give the HTML embed element a class or ID so you can style it with CSS. You can add a class or ID by selecting the HTML embed element, navigating to the Styles panel on the right sidebar, and entering a class or ID in the appropriate field.

  5. Style the HTML embed: Use CSS to give the HTML embed element the appearance you desire. This can include adjusting the position, background color, border, and other visual properties.

  6. Add a click event listener with JavaScript: To make the iframe clickable, you need to add a click event listener to the HTML embed element. You can do this by adding the following JavaScript code to the page's custom code:

<script>  const iframeElement = document.getElementById("your-iframe-id");  iframeElement.addEventListener("click", function() {    // Replace "your-iframe-id" with the ID you gave to the HTML embed element    window.open("https://your-iframe-url.com");     // Replace "https://your-iframe-url.com" with the URL you want the iframe to navigate to when clicked  });</script>
  1. Replace the iframe ID and URL: In the JavaScript code above, replace "your-iframe-id" with the ID you gave to the HTML embed element, and replace "https://your-iframe-url.com" with the URL you want the iframe to navigate to when clicked.

  2. Publish and test: Once you've added the code and styled the HTML embed element, publish your Webflow site to see the iframe become clickable. Test it by clicking on the iframe and confirming that it navigates to the desired URL.

By following these steps, you can make your iframe clickable in Webflow and provide users with a seamless experience when interacting with embedded content.

Additional Questions:

  • How do I customize the appearance of my iframe in Webflow?
  • Can I embed multiple iframes on a single Webflow page?
  • Is it possible to make the iframe open in a new tab when clicked?