search

Iframes in HTML

Sep 04, 2024 pm 04:41 PM
htmlhtml5HTML TutorialHTML PropertiesHTML tags

Iframes in HTML are nothing but inline frames used as an HTML document to add another HTML document into it. It’s mostly used in web pages or web development processes to include other content through another source like advertisements on that webpage.

Most web designers use Iframe to present interactive applications on the website or web pages. It’s made possible using JavaScript or the target attribute in HTML.

The main purpose of an Iframe is to display a web page within another. The inline frame should be displayed using a tag called

Syntax

  • Now we will see how exactly Iframe is going to use:
<iframe src="URL"></iframe>
  • Here

Example:

<iframe src="www.educba.com"></iframe>
  • It is also possible to give some specific height and width to our Iframe in pixels format as follows:
<iframe src="URL" height="value" width="value"></iframe>
  • In the above syntax, all things will be going to same; additionally, we can specify height and width in pixels format, defining them as

Example:

<iframe src="www.educba.com" height="300" width="300"></iframe>
  • One more method for defining the height and width of the iframe by using values through CSS is shown in the syntax below:
<iframe src="URL" style="height: value in pixels; width: value in pixels"></iframe>
  • All things are the same as above, just doing a change in specifying values.

Example:

<iframe src="www.educba.com" style="height:300px; width:300px;"></iframe>
  • One more feature that gets added to the iframe is we can remove already defined borders to the frame by using border none property. The syntax for this is as follows:
<iframe src="URL" style="border : none;"></iframe>
  • With the help of CSS, it’s also possible to do many things with the border, like changing its size, applying some color to the border, etc.

The iframe can be used as Target for a link by using the syntax:

<iframe src="URL" name="iframe_a"></iframe>
  • In the above syntax, src is our normal URL; here, the link’s target attribute will refer to the name attribute in our iframe tag.

Example:

<iframe src="www.educba.com" name="iframe_a"></iframe>

Iframes Tag Attribute

There are different attribute tags used in Iframes. Those are as follows:

  • Src: This attribute is used to insert a file that needs to be included in the frame. URL specifies the target webpage to be loaded within an iframe.
  • Name: Name is an attribute used to give some identification name to the frame. It’s most useful when you are creating one link to open another webpage.
  • allowfullscreen: This attribute allows you to display your frame in the full-width format. So we have to set the value true to happen to this function.
  • Frameborder: This is a helpful attribute that allows you to show a border or not to show the border to the frame. Value 1 is to show the border & 0 is not to show the border to the frame.
  • Marginwidth: Allows you to define space between the left & right sides of the frame.
  • Marginheight: This allows you to define space between the top & bottom of the frame.
  • Scrolling: These attributes control whether the scrollbar will show or not in the frame. The values included are ‘yes’, ‘ no,’ or ‘auto.’
  • Height: It is used to define the height of the frame. Whether in % or pixels
  • Width: It is used to define the width of the frame. Whether in % or pixels
  • Longdesc: With the help of this attribute, you can link another page with a lengthy description of the contents of your frame.

Examples of Iframes in HTML

Here are some examples of Iframes in HTML, which are explained below:

Example #1

Let’s consider one example where we will show how to create an iframe with a specific height and width.

Code:



<h2 id="HTML-Iframes-Demo">HTML Iframes Demo</h2>
<p>Here, we are showing an example of Iframe which containing specific Height and width in pixels format</p>
<iframe src="C:%5CUsers%5CSonali%5CDesktop%5CHTML%20block%20elements.html" height="300" width="300"></iframe>

Output:

Iframes in HTML

Example #2

Let’s consider another example where we will show how to create an iframe with a specific height and width. But in this example, we are specifying height and width through CSS. Here we can see the scroll bar is being adjusted per content size.

Code:



<h2 id="HTML-Iframes-Demo">HTML Iframes Demo</h2>
<p>Here, we are showing an example of Iframe which containing specific Height and width in pixels format</p>
<iframe src="C:%5CUsers%5CSonali%5CDesktop%5CHTML%20block%20elements.html" style="height:100px;width:300px;"></iframe>

Output:

Iframes in HTML

Example #3

Here we are considering one example in which we will add a border to the iframe by adding some extra CSS properties to show a change in the border’s size, change in the border color, etc. So we can add as much style to our iframe.

Code:



<h2 id="HTML-Iframes-Demo">HTML Iframes Demo</h2>
<p>Here we are showing an example of Iframe which containing a border with some additional CSS proprties</p>
<iframe src="C:%5CUsers%5CSonali%5CDesktop%5Ciframe.html" style="border:3px solid Blue; height: 200px;"></iframe>

Output:

Iframes in HTML

Example #4

Let’s consider another example where we will show how the target attribute opens a webpage link using an iframe.

Code:



<h2 id="Iframe-Demo-Target-for-a-Link">Iframe Demo- Target for a Link</h2>
<iframe height="200px" width="100%" src="C:%5CUsers%5CSonali%5CDesktop%5Ciframe1.html" name="iframe1_a"></iframe> <p><a href="https://www.educba.com/courses/">EDUCBA</a></p>
<p>When the target of a link matches the name of an iframe, the link will open in the iframe.</p>

Output:

Iframes in HTML

Target Output:

As shown above, for example, we can click on the target link EDUCBA so that it will open the following web page shown below.

Iframes in HTML

Conclusion

An iframe is an inline frame that includes another HTML document in itself. It is the most powerful HTML element for web designing. You can add content from another source. It uses different HTML attributes like Global Attributes, Event Attributes, etc.

The above is the detailed content of Iframes in HTML. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Why are HTML tags important for web development?Why are HTML tags important for web development?May 02, 2025 am 12:03 AM

HTMLtagsareessentialforwebdevelopmentastheystructureandenhancewebpages.1)Theydefinelayout,semantics,andinteractivity.2)SemantictagsimproveaccessibilityandSEO.3)Properuseoftagscanoptimizeperformanceandensurecross-browsercompatibility.

Explain the importance of using consistent coding style for HTML tags and attributes.Explain the importance of using consistent coding style for HTML tags and attributes.May 01, 2025 am 12:01 AM

A consistent HTML encoding style is important because it improves the readability, maintainability and efficiency of the code. 1) Use lowercase tags and attributes, 2) Keep consistent indentation, 3) Select and stick to single or double quotes, 4) Avoid mixing different styles in projects, 5) Use automation tools such as Prettier or ESLint to ensure consistency in styles.

How to implement multi-project carousel in Bootstrap 4?How to implement multi-project carousel in Bootstrap 4?Apr 30, 2025 pm 03:24 PM

Solution to implement multi-project carousel in Bootstrap4 Implementing multi-project carousel in Bootstrap4 is not an easy task. Although Bootstrap...

How does deepseek official website achieve the effect of penetrating mouse scroll event?How does deepseek official website achieve the effect of penetrating mouse scroll event?Apr 30, 2025 pm 03:21 PM

How to achieve the effect of mouse scrolling event penetration? When we browse the web, we often encounter some special interaction designs. For example, on deepseek official website, �...

How to modify the playback control style of HTML videoHow to modify the playback control style of HTML videoApr 30, 2025 pm 03:18 PM

The default playback control style of HTML video cannot be modified directly through CSS. 1. Create custom controls using JavaScript. 2. Beautify these controls through CSS. 3. Consider compatibility, user experience and performance, using libraries such as Video.js or Plyr can simplify the process.

What problems will be caused by using native select on your phone?What problems will be caused by using native select on your phone?Apr 30, 2025 pm 03:15 PM

Potential problems with using native select on mobile phones When developing mobile applications, we often encounter the need for selecting boxes. Normally, developers...

What are the disadvantages of using native select on your phone?What are the disadvantages of using native select on your phone?Apr 30, 2025 pm 03:12 PM

What are the disadvantages of using native select on your phone? When developing applications on mobile devices, it is very important to choose the right UI components. Many developers...

How to optimize collision handling of third-person roaming in a room using Three.js and Octree?How to optimize collision handling of third-person roaming in a room using Three.js and Octree?Apr 30, 2025 pm 03:09 PM

Use Three.js and Octree to optimize collision handling of third-person roaming in the room. Use Octree in Three.js to implement third-person roaming in the room and add collisions...

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools