Open In App

How to Create a Transparent iframe?

Last Updated : 18 Jun, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The <iframe> tag is an inline frame. It is used to embed another HTML page within the current HTML page.

Syntax

<iframe src = "URL"></iframe>

Approach

In this approach we will use iframe tag to create the iframe and A transparent iframe can be made by setting its background to transparent. And, the allowtransparency attribute of “iframe” is to be set as “true”. we are going to create a separate "iframe.html" page that will render into another HTML file as an iframe and we are using CSS to set the transparent background.

<iframe src = "URL" allowtransparency = "true"></iframe> 

Example: This example shows the creation of transparent iframe.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width, initial-scale=1.0">
    <title>Transparent Iframe Example</title>
    <style>
        .transparent-iframe {
            background-color: transparent;
            border: none;
            width: 400px;
            height: 400px;
        }
    </style>
</head>

<body>

    <iframe class="transparent-iframe" src="./iframe.html" 
            allowtransparency="true"></iframe>

</body>

</html>
HTML
// iframe.html

<!DOCTYPE html>
<html>
<style>
    p {
        height: 500px;
        width: 500px;
    }
</style>
<body>
    <div>
        <p> Hello there welcome to GFG.
            We learn CS and ither things here..
        </p>
    </div>
</body>

</html>

Output:

iframeeeee
output

Next Article

Similar Reads