HTML Iframes
An HTML iframe is used to display a web page within a web page.
Iframe Syntax
The HTML <iframe> tag specifies an inline frame.
Example: Basic Iframe
html
<iframe src="https://www.w3schools.com" title="W3Schools Free Online Web Tutorials" width="300" height="200"></iframe>It is a good practice to always include a title attribute for the <iframe>. This is used by screen readers to read out what the content of the iframe is.
Iframe - Height and Width
Use the height and width attributes to specify the size of the iframe. You can also use CSS to set the size.
Iframe - Target for a Link
An iframe can be used as the target frame for a link. The target attribute of the link must refer to the name attribute of the iframe.
Example: Iframe as a Target
html
<iframe src="demo_iframe.htm" name="iframe_a" height="300px" width="100%" title="Iframe Example"></iframe>
<p><a href="https://www.w3schools.com" target="iframe_a">W3Schools.com</a></p>Test Yourself with an Exercise
Which attribute specifies the URL of the page to show in an iframe?