{"id":13714,"date":"2018-12-23T22:10:29","date_gmt":"2018-12-23T22:10:29","guid":{"rendered":"https:\/\/www.hostinger.com\/tutorials\/?p=13714"},"modified":"2026-11-06T09:05:08","modified_gmt":"2026-11-06T09:05:08","slug":"what-is-iframe","status":"publish","type":"post","link":"\/my\/tutorials\/what-is-iframe\/","title":{"rendered":"What is an iframe?"},"content":{"rendered":"<?xml encoding=\"utf-8\" ?><p class=\"wp-block-paragraph\">An iframe (inline frame) is an HTML element that embeds another webpage or HTML document within the current page. Websites commonly use iframes to display videos, maps, forms, and other external content without redirecting visitors to another website.<\/p><p class=\"wp-block-paragraph\">For example, you can embed a YouTube video or Google Maps location directly into a webpage using the <code>&lt;iframe&gt;<\/code> tag. Visitors can interact with the embedded content while staying on your website. However, iframes also come with security, accessibility, and performance considerations, especially when displaying content from third-party sources.<\/p><p class=\"wp-block-paragraph\">In this guide, you&#8217;ll learn how iframes work, how to add one to your website using HTML, and which attributes to use. We&#8217;ll also cover common embedding issues and best practices for keeping iframe content accessible and secure.<\/p>\n\n\n\n<\/p><h2 id=\"h-how-does-an-iframe-work\" class=\"wp-block-heading h-t-title-2\">How does an iframe work?<\/h2><p class=\"wp-block-paragraph\">An iframe creates a separate browsing area within a webpage and loads another <a data-click-id=\"hgr-post-content-link-html\" href=\"\/my\/tutorials\/what-is-html\/\">HTML<\/a> document inside it.<\/p><p class=\"wp-block-paragraph\">For example, when you embed a YouTube video, the video player runs inside an iframe while the rest of your website remains outside it.<\/p><p class=\"wp-block-paragraph\">The embedded content has its own document and browsing context. Browsers also apply security restrictions to interactions between documents from different origins.<\/p><h2 id=\"h-how-to-embed-content-using-an-iframe\" class=\"wp-block-heading h-t-title-2\">How to embed content using an iframe<\/h2><p class=\"wp-block-paragraph\">To embed external content, add the <code>&lt;iframe&gt;<\/code> element to your HTML document and specify the content&#8217;s URL using the <code>src<\/code> attribute.<\/p><p class=\"wp-block-paragraph\">For example, the following code <a data-click-id=\"hgr-post-content-link-embeds-a-youtube-video\" href=\"\/my\/tutorials\/how-to-embed-video-in-wordpress\/\">embeds a YouTube video<\/a>:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;iframe\n  src=\"https:\/\/www.youtube.com\/embed\/dXBohfjc4WA\"\n  title=\"Hostinger video tutorial\"\n  width=\"680\"\n  height=\"383\"\n  loading=\"lazy\"\n  allowfullscreen&gt;\n&lt;\/iframe&gt;<\/pre><div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" width=\"900\" height=\"666\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2018\/12\/iframe-example-youtube-code.jpg\/public\" alt=\"Iframe Example\" class=\"wp-image-13724\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2018\/12\/iframe-example-youtube-code.jpg 900w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2018\/12\/iframe-example-youtube-code-150x111.jpg 150w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2018\/12\/iframe-example-youtube-code-300x222.jpg 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2018\/12\/iframe-example-youtube-code-768x568.jpg 768w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/figure><\/div><p class=\"wp-block-paragraph\">The example uses several iframe attributes:<\/p><ul class=\"wp-block-list\">\n<li><code>src<\/code> &ndash; specifies the URL of the embedded document.<\/li>\n\n\n\n<li><code>title<\/code> &ndash; describes the iframe&#8217;s content for people using assistive technologies.<\/li>\n\n\n\n<li><code>width<\/code> and <code>height<\/code> &ndash; define the iframe&#8217;s dimensions in CSS pixels.<\/li>\n\n\n\n<li><code>loading=\"lazy\"<\/code> &ndash; delays loading an offscreen iframe until it approaches the viewport.<\/li>\n\n\n\n<li><code>allowfullscreen<\/code> &ndash; permits fullscreen display when supported by the embedded content.<\/li>\n<\/ul><p class=\"wp-block-paragraph\">You can adjust the dimensions or use CSS to make the iframe responsive on different screen sizes.<\/p><h3 class=\"wp-block-heading h-t-title-3\">Why isn&#8217;t my iframe displaying?<\/h3><p class=\"wp-block-paragraph\">An iframe may fail to display when the source website doesn&#8217;t permit its content to be embedded.<\/p><p class=\"wp-block-paragraph\">Some websites use security headers such as <code>X-Frame-Options<\/code> or Content Security Policy&#8217;s <code>frame-ancestors<\/code> directive to prevent other websites from embedding their pages.<\/p><p class=\"wp-block-paragraph\">If your iframe doesn&#8217;t load, verify that the URL is correct and that the source website supports embedding. For services such as YouTube, use their official embed URL rather than the regular page URL.<\/p><h2 id=\"h-are-iframes-safe-to-use\" class=\"wp-block-heading h-t-title-2\">Are iframes safe to use?<\/h2><p class=\"wp-block-paragraph\">Iframes are generally safe when you embed content from trusted sources, but they can introduce security and privacy risks if the embedded website is malicious or compromised.<\/p><p class=\"wp-block-paragraph\">Follow these practices when using iframes:<\/p><ul class=\"wp-block-list\">\n<li>Embed content only from trusted websites using <a data-click-id=\"hgr-post-content-link-https\" href=\"\/my\/tutorials\/http-vs-https\/\">HTTPS<\/a>.<\/li>\n\n\n\n<li>Add a descriptive <code>title<\/code> attribute to support accessibility.<\/li>\n\n\n\n<li>Use <code>loading=\"lazy\"<\/code> for offscreen embeds to reduce unnecessary loading.<\/li>\n\n\n\n<li>Consider the <code>sandbox<\/code> attribute when you need to restrict what embedded content can do.<\/li>\n<\/ul><p class=\"wp-block-paragraph\">The <code>sandbox<\/code> attribute can restrict actions such as running scripts, submitting forms, and opening new windows. However, these restrictions may prevent some interactive embeds from working, so test them before publishing.<\/p><figure class=\"wp-block-image size-full\"><a data-click-id=\"hgr-post-content-link-my-web-hosting\" href=\"\/my\/web-hosting\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/11\/Web-hosting_in-text-banner.png\/public\" alt=\"Hostinger web hosting banner\" class=\"wp-image-98604\" srcset=\"https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2023\/11\/Web-hosting_in-text-banner.png 1024w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2023\/11\/Web-hosting_in-text-banner-300x88.png 300w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2023\/11\/Web-hosting_in-text-banner-150x44.png 150w, https:\/\/www.hostinger.com\/my\/tutorials\/wp-content\/uploads\/sites\/45\/2023\/11\/Web-hosting_in-text-banner-768x225.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n<h2 id=\"h-conclusion\" class=\"wp-block-heading h-t-title-2\">Next steps: Test your embedded content<\/h2><p class=\"wp-block-paragraph\">After adding an iframe to your website, preview the page to confirm that the embedded content loads correctly.<\/p><p class=\"wp-block-paragraph\">Test it on both desktop and mobile devices, especially if you&#8217;ve customized its width and height. Make sure visitors can interact with the embedded content and that it doesn&#8217;t interfere with the rest of the page.<\/p><p class=\"wp-block-paragraph\">If you&#8217;re embedding a third-party service, review its official embedding instructions and security requirements before publishing.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>An iframe (inline frame) is an HTML element that embeds another webpage or HTML document within the current page. Websites commonly use iframes to display videos, maps, forms, and other external content without redirecting visitors to another website. For example, you can embed a YouTube video or Google Maps location directly into a webpage using [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/my\/tutorials\/what-is-iframe\/\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":100,"featured_media":138230,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"What Is an iframe? HTML Examples, Uses, and Security","rank_math_description":"Learn what an iframe is, how it embeds external content in HTML, and how to use the iframe tag with accessibility, performance, and security in mind.","rank_math_focus_keyword":"what is iframe","_content_updated_date":"2018-12-24","footnotes":""},"categories":[22665],"tags":[],"class_list":["post-13714","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-website"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/what-is-iframe\/","default":0},{"locale":"pt-BR","link":"https:\/\/www.hostinger.com\/br\/tutoriais\/o-que-e-iframe\/","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/quest-ce-qu-un-iframe\/","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/que-es-iframe\/","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/apa-itu-iframe\/","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/what-is-iframe\/","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/what-is-iframe\/","default":0},{"locale":"en-GB","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/what-is-iframe\/","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/what-is-iframe\/","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/what-is-iframe\/","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/what-is-iframe\/","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/what-is-iframe\/","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/que-es-iframe\/","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/que-es-iframe\/","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/que-es-iframe\/","default":0},{"locale":"pt-PT","link":"https:\/\/www.hostinger.com\/pt\/tutoriais\/o-que-e-iframe\/","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/posts\/13714","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/users\/100"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/comments?post=13714"}],"version-history":[{"count":29,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/posts\/13714\/revisions"}],"predecessor-version":[{"id":138229,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/posts\/13714\/revisions\/138229"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/media\/138230"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/media?parent=13714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/categories?post=13714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/tags?post=13714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}