Facebook Page Embed Iframe Not Filling Width? Fix It
In this article
The Facebook Page embed iframe often does not fill its container because Facebook's plugin code sets a fixed pixel width (usually 500px) and the iframe's width attribute is not set to 100%. You can fix it by editing the embed code to use width="100%" and adding a CSS rule that forces the iframe to stretch. This guide walks through the exact changes, common pitfalls, and how to make the embed responsive on any screen size.
What You'll Need
- Access to the HTML of the page where the embed appears (a website, blog, or CMS custom HTML block).
- The original Facebook Page plugin embed code (from the Page's Plugins section or the Page Plugin configurator).
- Basic ability to edit HTML attributes and add a small CSS rule.
Step-by-Step
- Locate the iframe in your embed code. The Facebook Page plugin code contains an
<iframe>tag with attributes likesrc,width,height, andstyle. If you used the configurator, the width is usually a number such as500. - Change the width attribute to 100%. Replace
width="500"(or whatever number is there) withwidth="100%". Do not remove the attribute entirely; some browsers render iframes at a default 300px width if no width is specified. - Remove any fixed width in the inline style. If the iframe has
style="width:500px;"or similar, delete that width declaration or change it towidth:100%;. Inline styles override the width attribute, so this step is critical. - Add a CSS rule for the iframe. In your stylesheet or a
<style>block, add:iframe.facebook-page-embed { width: 100% !important; max-width: 100%; border: none; overflow: hidden; }
Then add the classfacebook-page-embedto the iframe tag. The!importantensures the rule wins over any inline or theme styles. - Set a responsive height. Facebook's embed uses a fixed height (often 500–700px). To keep the aspect ratio on small screens, you can wrap the iframe in a container with
position: relative; padding-bottom: 130%;and set the iframe toposition: absolute; top:0; left:0; width:100%; height:100%;. Adjust the padding percentage to match your desired height-to-width ratio. - Check the parent container. If the iframe still does not stretch, an ancestor element may have a fixed width or
display: flexthat constrains it. Inspect the container in your browser's developer tools and ensure it haswidth: 100%and nomax-widthsmaller than the viewport. - Test on multiple screen sizes. Resize your browser window or use device emulation to confirm the iframe fills the container on desktop, tablet, and phone. The Facebook content inside the iframe will scale, but the iframe itself should now span the full width.
Common Mistakes
- Leaving the width attribute as a number. Setting
width="100%"is required; a numeric width like500will always render at 500px regardless of CSS unless overridden. - Forgetting inline styles. If the iframe has
style="width:500px", your external CSS may not apply without!important. Always check the style attribute. - Using a fixed-height wrapper. A parent
<div>with a fixed pixel width will clip the iframe. Ensure the wrapper is fluid. - Not accounting for Facebook's own responsive behavior. The Page plugin inside the iframe may not reflow perfectly at very narrow widths; test and adjust the height if content gets cut off.
- Editing the wrong iframe. Pages often have multiple iframes (ads, videos). Confirm you are editing the one with
facebook.com/plugins/page.phpin thesrc.
Tips
- Use the Facebook Page Plugin configurator to generate fresh embed code, then apply the width changes. This avoids outdated markup.
- If you use a CMS like WordPress, place the embed in a Custom HTML block and add the CSS to your theme's Additional CSS section.
- For a cleaner look, set
border: none;andoverflow: hidden;on the iframe to remove default borders and scrollbars. - Consider using
loading="lazy"on the iframe to improve page load performance, especially if the embed is below the fold. - If the iframe content appears blurry on high-DPI screens, ensure the iframe's height is sufficient; Facebook's plugin may render at a fixed internal resolution.
Troubleshooting
If the iframe still does not fill the container after the steps above, work through these checks in order:
- Inspect the element. Right-click the iframe and choose Inspect. Look at the computed width and any overridden rules. The browser will show which CSS rule is winning.
- Check for conflicting CSS. Theme or framework styles (e.g., Bootstrap's
.embed-responsive) may set a max-width. Override with a more specific selector or!important. - Verify the parent container's width. Use the developer tools to select the parent and confirm its width is not fixed. If it is, change it to
width: 100%or use a fluid layout. - Test with a minimal HTML page. Create a blank page with only the iframe and your CSS. If it works there, the issue is in your site's CSS or layout.
- Clear caches. Browser and server caches may serve old CSS. Hard-refresh (Ctrl+F5) and clear any caching plugin.
- Check Facebook's plugin behavior. The Page plugin may have a minimum width (around 180px) and maximum width (500px) for its internal content. The iframe can be wider, but the content inside may not stretch beyond 500px. This is a limitation of the plugin, not your code.
Frequently Asked Questions
Why does my Facebook embed stay at 500px wide?
The default embed code sets a fixed width of 500px. You must change the width attribute to 100% and remove any inline width styles.
Can I make the Facebook Page plugin fully responsive?
Yes, by setting the iframe width to 100% and using a responsive wrapper for height. However, the content inside the iframe may not scale perfectly below 180px or above 500px due to Facebook's internal layout.
Does the Facebook Page plugin work on mobile?
Yes, the iframe will render on mobile browsers, but the internal content may be cramped on very small screens. Test and adjust the height as needed.
Why is there a scrollbar inside the iframe?
The iframe height is too small for the content. Increase the height attribute or use a responsive wrapper with a larger padding-bottom percentage.
Can I use CSS to override the iframe width without editing the embed code?
Yes, add a CSS rule targeting the iframe (e.g., iframe[src*="facebook.com/plugins/page"] { width: 100% !important; }). This works if your CSS loads after Facebook's inline styles or uses !important.
What if the iframe still doesn't fill the container after all steps?
Check for a parent element with a fixed width or display: flex that constrains the iframe. Also verify that no other CSS rule with higher specificity is setting a width.