Iframe tutorial LEARNOVITA

HTML iframe Tutorial | Learn All about Tags and Element

Last updated on 12th Aug 2022, Blog, Tutorials

About author

Yeshwant singh (Html Developer )

Yeshwant Singh is an Html Developer with 6+ years of experience in a reputed company. He has expertise in HTML and CSS, PHP and MySQL, Javascript, and Node JS. He spends most of his time researching technology and startups.

(5.0) | 17289 Ratings 1995

What Is an iFrame?

An iFrame, also knowns as an Inline Frame, is an element that loads the another HTML element inside of a web page. They are generally used to embed specific content like external ads, videos, tags, or other interactive elements into the page.So, I may be wondering how it’s done. Chances are the web designer put an iFrame element within the page..such tag is the <"iframe"> tag; this tag is used for embedding a document within the document.

For example: embedding maps on a webpage or the youtube video on a web site.This article aims to focus on the HTML Iframes tag and its implementation.It is a more important HTML tag since more web applications need embedded elements like maps, web advertisements, etc.HTML is critical for web development, and if ever thought about choosing web development as a career path, unquestionably have come across this language.And that’s probably why they are here in the first place.

What is an HTML Iframe tag?

  • HTML is nothing but the tags that it constitutes.
  • HTML has a tag for almost each element that you can think of adding to a web page.
  • <"iframe"> is one of the most important tags often used to embed the other documents like web pages, maps, etc.
  • The iframe in HTML stands for an Inline Frame.
  • The <"iframe"> tag explains a rectangular area within the current document or web page.
  • The web browser can show another document within the current page, including scrollbars and borders.
  • Like every other tag, the <"iframe> tag also has some attributes associated with it.
  • Attributes like src, height, width, and others explain and edit the region created by <"iframe"> tag.
What Is an iFrame


  • <"iframe src="URL of document" title="description of document""><"/iframe">

Set Width and Height of iframe:

  • Can set the width and height of an iframe by using “width” and “height” attributes.
  • By default, the attribute values are specified in the pixels but can also set them in percent. i.e. 50%, 60% etc.

Remove the border of iframe:

  • By default, an iframe contains a border around it.
  • can remove the border by using a <"style"> attribute and a CSS border property.

Embed YouTube video using iframe:

can also add a YouTube video on the webpage using the <"iframe"> tag.The attached video will be played at the webpage and that can also set height, width, autoplay, and many more properties for the video.Following are some steps to add YouTube video on a webpage:

  • Goto YouTube videos which need to be embedded.
  • Click on SHARE ➦ under the video.
  • Click on Embed <""> option.
  • Copy HTML code.
  • Paste the code in the HTML file
  • Change height, width, and other properties (as per requirement).

Attributes of <"iframe">:

    Attribute nameValueDescription
    allowfullscreen If true then that frame can be opened in full screen.
    height Pixels It explains the height of an embedded iframe, and the default height is 150 px.
    name text It gives the name to the iframe. The name attribute is important if you need to create a link in one frame.
    frameborder 1 or 0 It explains whether an iframe should have a border or not. (Not supported in HTML5).
    Width Pixels It explains the width of the embedded frame, and the default width is 300 px.
    src URL The src attribute is used to give the path name or file name which content to be loaded into an iframe.
    sandbox This attribute is used to apply n extra restrictions for the content of a frame
    sandbox allow-forms It allows submission of the form if this keyword is not used then form a submission is to be blocked.
    sandbox allow-popups It will enable pop ups, and if not applied then no popup will be open.
    sandbox allow-scripts It will enable a script to run.
    sandbox allow-same-origin If this keyword is used then an embedded resource will be treated as a downloaded resource from the same source.
    srcdoc The srcdoc attribute is used to display the HTML content in the inline iframe. It overrides a src attribute (if a browser supports).
    scrolling It indicates whether the browser should offer a scroll bar for the iframe or not. (Not supported in HTML5)
    scrolling auto Scrollbar only displays if the content of the iframe is larger than its dimensions.
    scrolling yes Always display a scroll bar for the iframe.
    scrolling no Never display a scrollbar for the iframe.

How to Use iFrame:

  • Should not use an iFrame excessively.
  • It can slow down the page and pose a security risk, especially if you use content from a suspicious website.
  • Think about an iFrame as a part of a content, but not part of the site.
  • For example: if I need to add a YouTube video to stimulate readers, then I can insert an iFrame element to that post.

Related: How to Embed Video in WordPress:

Now I know that iFrame is an additional element to share the content from other sites.Can add it to give a context about a certain topic to the readers.Can insert an iFrame element by using the <"iframe"> tag in the HTML document., and save the file as .html format.

Security Threats of Using iFrame:

By nature, the iFrame element does not pose any security risk for the web page or readers.Partly, it was developed to help content makers add visually engaging material to readers.Nevertheless, you are required to pay attention when adding an iFrame from an untrusted site website.There was a surge of iFrame code injection on a few legitimate websites, like ABC news, in 2008.This type of an attack redirects visitors to a malicious site, which will then install a virus to the visitors’ PC or attempt to steal sensitive information.That is why it is not recommended to contain an iFrame as an integral part of a website.If you think that a website is not safe, don’t even bother to link it and don’t put its content in an iFrame element.

Advantages of the framework:

Advantages of the framework

Overloading a page without an overloading the full page requires only one frame page in the page to be overloaded (reducing the transmission of data and speeding up the download of the page)The technology is simple to grasp, easy to use, many users, can be majorly used in the search engine does not need to find the pagesimple to make navigation bar.

Disadvantages of the framework (the disadvantage of the IFRAME is similar to frame):

will produce a lot of pages, not simple to manage Not simple to print (currently can only achieve the sub-frame page printing, can not achieve frameset printing) The browser’s Back button is invalid. Only for the forward and backward of the page where the current cursor is placed, unable to frameset the full page forward and backward Code is difficult , can not be indexed by search engines (frame structure) can not set a title for every page (title), worse, some search engines on the frame structure of the page is not handled correctly, will affected the ranking of search results)Most small mobile devices (PDA phones) do not entirely display the frameMulti-frame pages improve HTTP requests from the serverDue to more of the above shortcomings, therefore does not conform to a standard web design concept, has been abandoned by a standard web design, the current HTML5 no longer support this label.

Disadvantages of IFrame:

1. The biggest disadvantage of using a frame structure in Web page is that the “spider” Program of search engine can not interpret this kind of page.When a “spider” Program encounters a webpage that consists of some frames, they see only the frame and cannot find the link, so they think the site is a dead site and soon turn around and leave.It’s a disaster for the website.If need to sell a product, need a customer, and if nee d a customer, first have to get people to visit a site, and to do that, have to turn to the search enginespend a lot of time, energy, and money opening an online store, but deliberately not allowing the search engines to retrieve that it’s like opening a retail store, but all the windows are to be painted black, and no sign is hanging.

2. frame structure sometimes confuses people, especially in some frames that appear up and down, left and right scroll bar.In addition to crowding out a very limited amount of the page space, these scrollbars distract visitors.Visitors who encounter this type of website will often turn away immediately.They will think that since the homepage is so confusing, the rest of the site may not be worth browsing.

3. link navigation problems. When using a frame structure, must ensure that all the navigation links are set correctly, as otherwise, it will cause a great inconvenience to the visitor.For example, the linked page appears in the navigation frame, in which case a visitor is trapped, because at this point ,has no other place to go.


All in all, iFrame is a powerful element if need more engagement for visitors.Think of iFrame as part of the content that it makes, not as an integral part of the website.shouldn’t use iFrame excessively though; it is better if I can develop a site without iFrame.If you still need to use it for development purposes, remember only to use content from a trustworthy site.

Are you looking training with Right Jobs?

Contact Us

Popular Courses