How to center an iframe horizontally with CSS?

Spread the love

Sometimes, we want to center an iframe horizontally with CSS.

In this article, we’ll look at how to center an iframe horizontally with CSS.

How to center an iframe horizontally with CSS?

To center an iframe horizontally with CSS, we use flexbox.

For instance, we write

<div style="display: flex; justify-content: center">
  <iframe></iframe>
</div>

to make the div a flex container with display: flex.

Thhen we use justify-content: center to center its contents horizontally.

Conclusion

To center an iframe horizontally with CSS, we use flexbox.

Leave a Reply

Your email address will not be published. Required fields are marked *