Home 〉 HTML Tutorials 〉 HTML iframe Tag - Embed External Content in Webpage | Guide with Examples
HTML iframe Tag - Embed External Content in Webpage | Guide with Examples !
What is the HTML iframe tag and how is it used to embed external content in a webpage?
The HTML '<iframe>' tag allows you to insert another webpage or content within your current page. It uses the 'src' attribute to define the content URL and can be styled using CSS. This tag supports attributes like 'loading', 'sandbox', 'title', and more to make content secure and accessible. It's an inline-level element and behaves like a replaced element. The details blog post on html iframe tag is as follows.
The '<iframe>' tag in HTML is used to embed another HTML page or external content (like videos, maps, or websites) into your current webpage. This feature is especially useful for showing dynamic or third-party content without redirecting users.
With the help of an iframe, you can display YouTube videos, Google Maps, forms, external blog posts, or even interactive tools within your site.
Syntax ✍
<iframe src="https://tut.shinecap.co.in" width="600" height="400" title="Embedded Content"></iframe>
The '<iframe>' tag is considered an inline-level element, but it behaves like a replaced element (like images or videos), meaning it has its own dimensions.
Specifies the URL of the document to embed.
<!DOCTYPE html>
<html>
<body>
<iframe src="https://tut.shinecap.co.in"></iframe>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Loads and displays 'tut.shinecap.co.in' in the iframe.
Set the dimensions of the iframe.
<!DOCTYPE html>
<html>
<body>
<iframe src="https://tut.shinecap.co.in" width="500" height="300"></iframe>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Displays the iframe with 500px width and 300px height.
Gives the iframe a title for screen readers.
<!DOCTYPE html>
<html>
<body>
<iframe src="https://tut.shinecap.co.in" title="Example Page"></iframe>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Helps with accessibility tools to identify the content.
Assigns a name to the iframe for targeting from links or scripts.
<!DOCTYPE html>
<html>
<body>
<iframe name="iframe1" src="https://tut.shinecap.co.in"></iframe>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
The iframe is identified as "iframe1", useful for links like '<a target="iframe1">'.
Allows full-screen mode for supported content like videos.
<!DOCTYPE html>
<html>
<body>
<iframe src="https://www.youtube.com/embed/videoid" allowfullscreen></iframe>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Enables full-screen button for the video.
Defines how the iframe should be loaded.
<!DOCTYPE html>
<html>
<body>
<iframe src="https://tut.shinecap.co.in" loading="lazy"></iframe>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
The iframe loads only when it comes into the viewport (improves page speed).
Restricts iframe functionality for security.
<!DOCTYPE html>
<html>
<body>
<iframe src="https://tut.shinecap.co.in" sandbox></iframe>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Applies strict rules to the iframe content (like blocking scripts, forms, etc.).
<!DOCTYPE html>
<html>
<body>
<iframe
src="https://tut.shinecap.co.in"
width="600"
height="400"
style="border: 2px solid #ccc; border-radius: 10px; padding: 5px; background-color: #f9f9f9;">
</iframe>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
The '<iframe>' tag is a powerful tool in HTML for embedding external content directly into your webpage. Whether it's a map, video, or another website, the iframe helps you deliver dynamic and interactive user experiences. It's important to use attributes like 'title', 'loading', and 'sandbox' responsibly to ensure accessibility, performance, and security.
Yes, YouTube provides an iframe embed code you can directly paste into your HTML.
No, you'll need to use CSS (like 'width: 100%') to make it responsive.
'<iframe>' can embed web pages, while '<embed>' is mostly used for media content like PDFs or Flash.
Using iframes can affect SEO slightly because search engines might not crawl iframe content. Use them wisely and keep critical content outside iframes.