IFrame src attribute

Definition and usage

src Sets or returns the src attribute of the iframe element src attribute value.

src attribute Specifies the URL of the document to be displayed in the iframe.

Example

Example 1

Change the URL of the document to be embedded in the iframe:

document.getElementById("myFrame").src = "https://wwf.org";

Try it yourself

Example 2

Get the URL of the document displayed in the iframe:

var x = document.getElementById("myFrame").src;

Try it yourself

Syntax

Return the src attribute:

iframeObject.src

Set the src attribute:

iframeObject.src = URL

Attribute value

Value Description
URL

Specifies the URL of the document to be embedded in the iframe.

Possible values:

  • Absolute URL - Points to another website (such as src="http://www.example.com/default.html")
  • Relative URL - Points to a file within the website (such as src="default.html").

Technical Details

Return Value: A string value representing the URL of the document embedded in the iframe. Returns the entire URL, including the protocol (such as http://).

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support

Related Pages

HTML Reference Manual:HTML <iframe> src Attribute