Hey everyone! I’m trying to figure out how to center the HTML output from my Google Sheet. You know that embed version you can get? That’s what I’m working with. I was wondering if there’s a way to make it centered on the page using ‘margin: auto’ or something similar.
I’ve been playing around with it but no luck so far. Does anyone know if this is even possible? Maybe through Google Apps Script? It would be great if I could keep using the same URL too.
Any help or ideas would be really appreciated! Thanks in advance!
hey there! i’ve had some luck with this before. try wrapping ur iframe in a container div and use flexbox. something like:
this should center it nicely without messing with the original url. hope that helps!
I’ve actually dealt with this issue before when embedding Google Sheets into my company’s internal dashboard. While ‘margin: auto’ doesn’t work directly on the iframe, I found a workaround that might help you.
Try wrapping the iframe in a div and applying the centering styles to that container instead. Something like this:
<div style="display: flex; justify-content: center;">
<iframe src="your-google-sheets-embed-url" ...></iframe>
</div>
This method keeps your original embed URL intact and centers the sheet nicely. You might need to adjust the iframe’s width to ensure it fits properly within your page layout.
If you need more control, you could look into using the Google Sheets API to fetch the data and create a custom display. But for most cases, this simple CSS trick should do the job.
Having worked extensively with embedded Google Sheets, I can offer another approach. Instead of modifying the iframe directly, consider using CSS Grid for centering. It’s a powerful and flexible layout system that works well for this scenario.
Add a container div around your iframe and apply these styles:
.sheet-container {
display: grid;
place-items: center;
width: 100%;
}
This method ensures your embedded sheet is centered both horizontally and vertically within its container. It’s responsive and maintains the original URL structure.
If you need to adjust the size, you can modify the iframe’s width and height attributes. This solution is clean, doesn’t require JavaScript, and works across different screen sizes.