dots Created with Sketch.
Yogesh Chauhan's Blog

What is iFrame in HTML? Why do we need it?

in HTML on July 10, 2019

Iframe displays a webpage within a webpage. You can include it in your HTML page using ‘iframe’ tag.

Checkout the syntax below.


<iframe src="URL of the webpage you want to display"></iframe>


It’s pretty simple to do that. Also, you can set width and height for the webpage inside. Let’s see how.


<iframe loading="lazy" src="URL of the webpage you want to display" height="500" width="800"></iframe>


OR


<iframe loading="lazy" src="URL of the webpage you want to display" height="100%" width="100%"></iframe>


OR


<iframe src="URL of the webpage you want to display" style="height:500pc;width=800px"></iframe>


As you can see there are more than one way to set the width and height of any element. You can use pixels(px) directly to specify the height and width or you can use percentage directly. Also, you can use inline CSS code or a separate CSS file with same code as inline.

One more thing you can do is adding border to make it look real nice with a border frame.


<iframe src="URL of the webpage you want to display" style="border:2px solid blue;"></iframe>


OR


<iframe src="URL of the webpage you want to display" style="border:none;"></iframe>


You have to specify border width in order to add a border for e.g. 2px solid black otherwise browser won’t add any borders.

There is one more interesting fact about the iframe which you can go for and users might love it as well. Look at the code below.


<iframe src="URL of the webpage you want to display" 
  style="border:2px solid blue;" name="websiteChange">
</iframe>
<p>
  <a href="https://www.wikipedia.org/" target="websiteChange" rel="noopener">
  Wikipedia</a>
</p>


As you can see, we can use iframe as a target frame of a link. The only condition is it must refer to the name of the iframe.

Demo

amazon

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Jul 22 Is there a CSS parent selector? #Jul 22 Difference between :where and :is in CSS #Jul 22 Does :is() pseudo selector hint at CSS preprocessing in the future? #Jul 22 Control Scrolling with CSS Scroll Snap #Jul 21 Control rendering using CSS content-visibility property #Jul 21 How to use @supports rule in CSS?
You might also like these
A complete guide to add responsive YouTube videos using HTML and CSSCSSHow to Hide HTML elements automatically after few seconds using JavaScript?HTMLHow to make a UILabel clickable in Swift 5?SwiftWhat is XP (Extreme Programming) and When should it be used?MiscellaneousQuery to increment or decrement value in MySQL ignoring negative valuesSQL/MySQLHow to create bouncing balls using HTML canvas and JavaScript?HTML3 Common Usability Mistakes In Web DesignUI/UXHow to host Google fonts on your server and add them using CSS?CSSWhat is PostgreSQL? How similar or different it is from SQL?PostgresIntroduction to components and templates Part 1: Component MetadataAngularHow to show confirmation alerts with OK and cancel buttons using Swift 5?SwiftHow to center an image horizontally and vertically?CSS