Skip to the tool
MyMidlist business directory logo
  1. Home
  2. Tools
  3. Responsive YouTube iFrame Generator
FREE YOUTUBE TOOL

Responsive YouTube iFrame Generator Make Embeds Fit Any Screen

Paste your YouTube embed code and get a mobile-responsive wrapper that fits any screen: desktop, tablet or phone.

Runs in your browser. Your code is not uploaded. Not affiliated with YouTube or Google.

What is a responsive YouTube iframe generator?

A responsive YouTube iframe generator turns the fixed-size embed code from YouTube into code that scales to any screen. Paste your embed code or video link, choose an aspect ratio such as 16:9, and copy the HTML and CSS it creates. The video then fills the width of a phone, tablet or desktop and keeps its shape. It is free and runs in your browser.

YouTube gives you an iframe with a fixed width and height, usually 560 by 315 pixels. On a narrow phone that video can spill past the edge of the screen or force visitors to scroll sideways. This tool wraps the iframe in a flexible box that holds the video’s proportions, so it always fits.

It helps bloggers, web designers, marketers and business owners. If you run a business in the Middle East and show videos on your website, you can also add your business to MyMidlist for free.

How to make a YouTube embed responsive

  1. Copy your YouTube embed code. On YouTube, open the video, press Share, then Embed, and copy the code. You can also paste a normal video link, a youtu.be link or a Shorts link.
  2. Paste it into the box. Paste the code or link into the box above and press Generate responsive iFrame.
  3. Choose the shape and width. Pick an aspect ratio such as 16:9 or 9:16, and an optional maximum width. The tool picks a sensible ratio from your original code.
  4. Set the extras. Turn on lazy loading, privacy-enhanced mode, related-video control, a start time or muted autoplay, and write a clear title for screen readers.
  5. Copy the HTML and CSS. Check the live preview on phone, tablet and desktop widths, then copy the HTML, the CSS, or both together, and paste them into your page.

You can also open this page with a link in the form ?url= followed by a video link, and the tool fills itself in.

Why fixed-size embeds break on mobile

The default code from YouTube looks like this: an iframe tag with width set to 560 and height set to 315. Those numbers are pixels, so they never change.

ScreenWidthWhat happens with a 560 px embed
Large desktop1200 px or moreFits, but may look small
Tablet768 pxFits
Large phone430 pxOverflows by about 130 px
Small phone360 pxOverflows by about 200 px, so the page scrolls sideways

A responsive wrapper fixes this by using a percentage width and an aspect ratio instead of fixed pixels. Pages that do not scroll sideways are easier to use on a phone, and Google recommends mobile-friendly pages.

Two ways to make an iframe responsive

MethodHow it worksBest for
CSS aspect-ratioOne line, such as aspect-ratio: 16 / 9, keeps the box in proportion as the width changesAlmost every site today. It is the default in this tool
Padding hackHeight is 0 and the bottom padding is a percentage of the width, such as 56.25% for 16:9Very old browsers that do not support aspect-ratio

Both methods place the iframe inside a wrapper box and stretch it to fill that box. The tool writes the correct numbers for any ratio you choose, so you never need to calculate the padding yourself.

Which aspect ratio should I choose?

RatioPadding valueUse it for
16:956.25%Standard YouTube videos. The default
4:375%Older videos and some presentations
21:942.857%Ultrawide and cinematic videos
1:1100%Square videos
9:16177.78%YouTube Shorts and vertical video

If you pasted the original embed code, the tool reads its width and height and selects the closest ratio for you.

What each option does

OptionWhat it addsWhy use it
Maximum widthA max-width in pixels on the wrapperStops the video becoming huge on wide screens
Center on pageAutomatic left and right marginsKeeps a narrow video in the middle
Lazy loadingloading="lazy" on the iframeSpeeds up pages with videos further down
Privacy-enhanced modeUses youtube-nocookie.comLimits tracking until a visitor plays the video
Limit related videosrel=0 in the addressShows related videos from the same channel
Start timestart= in secondsOpens the video at the part that matters
Muted autoplayautoplay=1 and mute=1Plays on load without sound. Use sparingly
TitleA title attributeLets screen readers describe the video

Using the code on your website

PlatformWhere to paste the HTMLWhere to paste the CSS
WordPressA Custom HTML blockAppearance, Customize, Additional CSS, or inside a style tag in the same block
ShopifyA Custom Liquid section or the theme’s Custom HTML blockThe theme’s custom CSS setting, or a style tag next to the HTML
Wix, Squarespace, WebflowThe platform’s embed or code blockThe site’s custom CSS area, or a style tag in the same block
Plain HTML siteWhere you want the video in the pageIn your stylesheet, or a style tag in the head

Menu names change as platforms update. If a builder removes your style tag, put the CSS in the site’s main custom CSS area instead.

Make video embeds faster and more accessible

  • Use lazy loading for videos below the first screen.
  • Avoid many embeds on one page. Each embed loads scripts from YouTube. Use one video, or links to the others.
  • Write a real title. “How to bake sourdough” is better than “video”.
  • Add the transcript or a summary under the video. It helps search engines, people who cannot play sound, and AI answer engines.
  • Mention the video in nearby text. A heading and a short intro tell search engines what the video is about.
  • Test on a real phone. Check portrait and landscape.

Troubleshooting

ProblemTry this
The tool says the code is not validPaste the full embed code from YouTube, or a link that starts with youtube.com or youtu.be.
The video is still not responsiveMake sure you pasted both the HTML and the CSS. Without the CSS the wrapper has no size.
There is a black gap or the video is cut offCheck the aspect ratio matches the video. Choose 9:16 for Shorts.
The video does not play in the previewA browser extension or network may be blocking YouTube. Test on your own page.
My builder removed the style tagPut the CSS in the site’s main custom CSS area.
The video is too big on desktopSet a maximum width, such as 800 pixels, and keep Center on page on.
The video does not autoplayBrowsers block autoplay in many cases. Muted autoplay works more often but is not guaranteed.

Privacy

The code you paste is processed in your browser and is not sent to MyMidlist. The live preview loads the video from YouTube, as a normal embed does, so YouTube may receive the usual request that any visitor to a page with an embedded video makes. Privacy-enhanced mode changes the address that your own site uses for its visitors.

Glossary

TermMeaning
iframeAn HTML element that shows another web page, such as a YouTube video, inside your page.
ResponsiveAdjusting to the size of the screen or container.
Aspect ratioThe shape of a box as width to height, such as 16:9.
Embed codeThe HTML that YouTube gives you to show a video on another site.
Lazy loadingWaiting to load something until the visitor is close to seeing it.
youtube-nocookie.comYouTube’s privacy-enhanced address for embeds.
WrapperThe box around the iframe that controls its size and shape.
ViewportThe visible area of a web page on a device.

Videos on a local business website

A short video on your homepage or service page can show your premises, products and team. Make sure it works well on a phone, because most visitors in the region browse on mobile.

  • Put the video where it helps. A tour on the About page or a demo on a product page works well.
  • Describe it in text. Add a heading and a short summary so search engines understand the page.
  • Add captions in Arabic and English. Many people watch without sound.
  • Link your listing. Add your website and YouTube channel to your MyMidlist profile.
  • Keep the page fast. Use lazy loading and avoid too many embeds.

Frequently asked questions

What is a responsive YouTube iframe?

A responsive YouTube iframe is a YouTube embed that scales to fit its container, so the video fills the width of a phone, tablet or desktop screen without overflowing and keeps its shape. It is made by wrapping the iframe in a box that keeps a fixed aspect ratio.

Why does my YouTube embed overflow on mobile?

The code from YouTube gives the iframe a fixed width and height in pixels, usually 560 by 315. On a phone narrower than that, the video is cut off or forces a sideways scroll. A responsive wrapper makes the width flexible and keeps the height in proportion.

How do I make a YouTube video responsive?

Paste the embed code into this tool, press Generate, and copy the HTML and CSS it gives you. The wrapper uses the CSS aspect-ratio property, or the older padding method if you choose it, so the video scales with its container.

What is the aspect-ratio CSS method?

It is one line of CSS, such as aspect-ratio: 16 / 9, that tells the browser to keep a box in that proportion as its width changes. It is supported by all current major browsers and is the simplest method.

When should I use the padding method?

Use it only if you must support very old browsers. It uses height: 0 and a percentage of bottom padding, such as 56.25% for 16:9, to hold the shape. It gives the same result with more code.

What aspect ratio should I use for YouTube?

Use 16:9 for standard videos, which is the default for YouTube embeds. Use 9:16 for Shorts, 4:3 for older videos and 21:9 for ultrawide or cinematic video. The tool also supports 1:1 and any custom ratio.

Does this work for YouTube Shorts?

Yes. Paste a Shorts link and the tool selects 9:16 with a narrow maximum width. YouTube’s standard embed shows Shorts in a vertical player.

What is privacy-enhanced mode?

It switches the embed address from youtube.com to youtube-nocookie.com. YouTube describes this mode as not storing information about visitors on your site unless they play the video. It is a useful option for sites that care about cookie consent.

Should I use lazy loading on a YouTube iframe?

Usually yes. Adding loading="lazy" tells the browser to wait to load the video until the visitor scrolls near it, which makes the page load faster. Do not use it for a video at the very top of the page that is visible immediately.

What does the title attribute do?

It gives the iframe a name that screen readers announce, so blind and low-vision visitors know what the embed is. Use a short description of the video, not just the word video.

Can I start the video at a certain time or autoplay it?

Yes. Enter a start time in seconds. Autoplay is added as muted autoplay, because browsers usually block autoplay with sound. Use autoplay sparingly, since it can annoy visitors and use their data.

Can I hide related videos at the end?

You can limit them. Turning on this option adds rel=0, which makes YouTube show related videos from the same channel instead of videos from other channels. YouTube no longer lets embeds hide related videos completely.

Will it work in WordPress, Shopify, Wix, Webflow and other builders?

Yes, as long as the builder lets you add custom HTML and CSS. Paste the HTML into a custom HTML block or embed element, and add the CSS to the page, the theme’s custom CSS area or the same block inside a style tag.

Does the tool upload or store my code?

No. Everything runs in your browser. Your code is not sent to MyMidlist. The live preview does load the video from YouTube, as any embedded video would.

Is this tool free?

Yes. It is free with no signup and no limits.

Is this tool affiliated with YouTube?

No. MyMidlist is not affiliated with or endorsed by YouTube or Google. YouTube is a trademark of Google LLC.

Promote your business for free

Add your company to MyMidlist, the verified business directory covering the UAE, Saudi Arabia, Qatar, Oman, Bahrain, Kuwait, Jordan and Turkey.

Add your listing

More free tools