How can I make an iframe and container responsive using CSS in Webflow?

Published on
September 22, 2023

To make an iframe and container responsive using CSS in Webflow, you can follow these steps:

  1. Add an HTML Embed element to your Webflow project where you want to display the iframe. You can find this element in the Add panel under Components.

  2. Paste the iframe code into the HTML Embed element. You can obtain the iframe code from the source where you want to embed it (e.g., YouTube, Vimeo, Google Maps, etc.).

  3. Give the HTML Embed element a class name. This will allow you to apply custom CSS styles to it.

  4. Select the HTML Embed element and go to the Styles panel. Click on the "+" button next to the selector field to create a new class style for the element.

  5. In the new class style, set the width to 100% to make the iframe element expand to the full width of its containing element.

  6. Set the height property to 0 and add a padding-bottom value to create a responsive aspect ratio for the iframe. The padding-bottom value should be calculated based on the height divided by the width and multiplied by 100%. For example, if the iframe has a height of 315 pixels and a width of 560 pixels, the padding-bottom value would be (315 / 560) * 100 = 56.25%. This ensures that the iframe maintains its aspect ratio when the viewport size changes.

  7. Apply the class style to the HTML Embed element by selecting it in the navigator panel and choosing the class style from the class selector dropdown in the Styles panel.

  8. Further customize the HTML Embed element or its parent container if needed by adjusting other CSS properties like margin, padding, or alignment.

By following these steps, you'll be able to create a responsive iframe and container using CSS in Webflow.

Additional Questions:

  1. How do I embed a YouTube video in Webflow?
  2. How can I center align a container in Webflow?
  3. What are some best practices for responsive web design in Webflow?