Center YouTube video in WordPress

Actually, this comes up quite often with people depending on how your WordPress site is setup and what theme you are using, this might seem like a very small and easy thing, by default iframe will be left aligned because its block level element and its normal if you see it on the left side

Follow this quick steps below on how to center your YouTube videos.

Step 1: 

let’s get iframe code from one of video from youtube, you need to click share button under video and then embed link:

Step 2:  

now, go ahead to your WordPress post/page editor and switch to text mode and past the code:

Iframe code:

<iframe width="560" height="315" src="https://www.youtube.com/embed/V6cNXL2TUIM" frameborder="0" allowfullscreen></iframe>

after this your video will be left aligned, like this:

Step 3:  

and finally, if we want to center video on the page we need to wrap it in the div element with css style text aligned to center, final code looks like this:

<div style="text-align: center;"><iframe width="460" height="215" src="https://www.youtube.com/embed/V6cNXL2TUIM" frameborder="0" allowfullscreen></iframe></div>

and this is the result:

 

Hopefully, this short little tutorial on how to center YouTube embed is helpful! If so, feel free to comment below.

Leave a Reply

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