Open In App
Related Articles

HTML | <iframe> sandbox Attribute

Improve Article
Improve
Save Article
Save
Like Article
Like

The sandbox attribute permits an additional set of restrictions for the content within the iframe.
When the sandbox attribute exists, and it will: 
 

  • treat the content as being from a singular origin
  • It blocks form submission
  • It blocks script execution
  • It disables APIs
  • It also preventing links from targeting other browsing contexts
  • It stop the content to navigate its top-level browsing context
  • block automatically triggered features (such as automatically playing a video or automatically focusing a form control)

The value of the sandbox attribute will either be simply sandboxed (then all restrictions are applied) or a space-separated list of pre-defined values which will take away the actual restrictions.
 

Syntax:  

<iframe sandbox="value">

Attribute Values 

  • no-values: applies all restriction
  • allow-forms: Re-enables form submission
  • allow-pointer-lock: Re-enables APIs
  • allow-popups: Re-enables popups
  • allow-same-origin: It allows the content of iframe to be treated as being from same origin
  • allow-scripts: Re-enables scripts
  • allow-top-navigation: It Allows the content of iframe to navigate its top-level browsing context

Example: 
 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML Iframe sandbox Attribute
    </title>
</head>
 
<body>
    <h1>GeeksforGeeks</h1>
 
    <h2>HTML IFrame sandbox Attribute</h2>
 
    
 
    <br>
    <br>
 
    <iframe id="GFGFrame"
            src="https://ide.geeksforgeeks.org/tryit.php"
            width="400"
            height="200"
            sandbox>
    </iframe>
</body>
 
</html>


Output: 
 

Supported Browsers:The browsers supported by HTML IFrame sandbox Attribute are listed below 

  • Google Chrome 4.0 and above
  • Edge 12.0 and above
  • Firefox 17.0 and above
  • Internet Explorer 10.0 and above
  • Opera 15.0 and above
  • Safari 5.0 and above
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 17 Jun, 2022
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials