<iframe> Tag Syntax

Rules for coding HTML iframe elements
<body>
   ...
   ... flow content expected ...
   <iframe>
      ... flow content ...
   </iframe>
   ...
</body>
Rules for coding HTML iframe elements

Make sure you understand the difference between a tag and element and are familiar with the definitions of namespace and other HTML terms.

  1. Include a iframe element where flow content is expected.
  2. Begin the iframe element with a starting <iframe> tag. The element name uses lower case letters and should be in the HTML namespace, which it will pick up automatically from the xmlns attribute on the <html> tag.
  3. Inside the <iframe> starting tag, include a src attribute with the URL of a source document for the iframe content, a srcdoc attribute with the HTML for the iframe content or both, in which case the srcdoc will be used if supported and the src document will be used as fallback content.
  4. Inside the iframe element, between the starting <iframe> tag and the ending </iframe> tag, code the inner HTML flow content.
  5. End the iframe element with a matching </iframe> closing tag.

<iframe> Content Model

Contents of the iframe element

Content: Empty. All properties are coded using attributes.

The iframe element is an empty element, with both a start tag and an end tag, not a void element. However, while it can have text content in documents being parsed as HTML, it must be empty in documents being parsed as xHTML or pure XML. Therefore in polyglot documents as recommended on this site, HTML comments should be the only code inside an iframe element.