How To Make Youtube Embeded Videos Responsive

So you have hit the issue where you have a responsive website and everything looks great, but then you notice that embeded videos do not correctly fit within your responsive design. Fear not this can be quickly fixed by adding a div around all of your embeded videos and a little bit of css to go along with it. If you are using something like TinyMCE to do this, then it might seem like a lot of work to have to manually add a div to all of the embed videos that you add. Well fear not it’s possible to do this automatically!

Start by going to the plugins folder of your TinyMCE install directory. I am using TinyMCE 4 so the plugin file contents may differ if you are using an older version. Either way the concept will remain the same. Search through the file and look for he following string. “Paste your embed code below”. This may differ for each version, the best way to test is to use TinyMCE and see what message pops up when you are adding the embed code. Using minified code makes this quite hard to find, but it’s possible.

You will see an onclick method just past this. This is the function that you need to modify. Inside of this function you will see the following code


Replace this line of code with the following.

a.insertContent("<div class='videoiframe'>"+g(this.toJSON())+"</div>")

If you save the file and test this you will see that the iframe is now being added with the div wrapped around of it. (you might need to have the tools that allow you to view the source code to check this). From now on any embeded iframe from youtube or any other video website, will have a div wrapped around it. This allows you to add some custom css that will make the video responsive.

Open up your css file and add the following code.

.videoiframe {
float: none;
clear: both;
width: 100%;
position: relative;
padding-bottom: 56.25%;
padding-top: 25px;
height: 0;
.videoiframe iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;

Save this and check your website again, any videos that have the “videoiframe” div wrapped around it will be responsive. This of course wont effect existing videos that were added before you made this change to TinyMCE, but at least now you can go back and edit the posts to add the div to all of the embeded videos and they will now be responsive without having to do any work modifying the source code.

Related Articles

Related Questions

Whirlpool Oven F6E6: Appliance Manager 1 Board Communication

I have a brand new Whirlpool oven W11I OM1 4MS2 H or (859991549450). I bought it alongside the microwave combi oven. I have had...

Whats the difference between the Tapo P100 and the P105?

There are a few different Tapo smart plugs. The P100 and P110 differ based on the smart power monitoring feature but where does the...

Time remaining keeps going up on Whirlpool dryer??

I have clothes in the dryer regularly and the time remaining shows on the display. There could be 10 mins remaining and if I...


Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Latest Tools

Memory Converter

Converting values between various metric measurements is usually quite simple as there will be 1000 of the smaller unit in the next larger unit....

Bitrate Converter

Below you will find a bitrate converter. This tool will allow you to enter a bitrate value, in one of many different formats and...

Aesthetic Text Generator

There are various ways to make your social media profile seem more unique, some of which are not as easy to implement as others....

Aspect Ratio Calculator For Images

Aspect ratio is the ratio between the height and width of an image. If you want to resize an image by 100 pixels, you...

Add Text To Image

Use this free tool to add text to an image. Simply select the image file that you want to overlay text onto and you...

JavaScript Multi-line String Builder

Javascript did not always support multi-line strings. If you attempted to create a string variable using quotes, putting a line break into the source...

Latest Posts

Latest Questions