HTML <iframe> data-* Attribute

The data-* attribute on a <iframe> tag attaches additional data to the iframe element. To create a custom attribute, replace the * with a lowercase string, such as data-id, data-status, or data-location.



A custom data-url attribute on an <iframe>.
The attribute value is not visible, but it is readable by JavaScript.

<iframe src=""

Using data-*

The data-* attribute allows you to add custom attributes to a <iframe> element.

The * part is replaced with a lowercase string, such as data-id, data-cost, or data-location.

An <iframe> element can have any number of data-* attributes, each with their own name.

These attributes usually store additional data about the iframe (e.g. id, options, variations, etc.).

Using data-* attributes reduces the need for Ajax requests to the server.

Note: The data-* attribute does not change the appearance of the iframe tag in any way.


<iframe data-*="value">

Note: The * can be any string, such as data-iddata-costdata-supplier,  etc.



Value Description
value A string value. Can be numeric, alphanumeric, JSON, etc.

More Examples

A custom data-link attribute in an <iframe> element.
Clicking the button will display the link value.

<iframe id="myiframe" src=""
        data-link="Wikipedia English Edition"

<button onclick="show();">Show data</button>

  let show = () => {
    let element = document.getElementById("myiframe");
    alert("Link = " + element.getAttribute('data-link'));

Code explanation

The <iframe> tag below contains a custom data-link attribute.

The data-link attribute specifies the description of the iframe URL.

Clicks are handled by the onclick event.

Onclick invokes a JavaScript function that extracts and displays the iframe url description.

Note: Notice how the url will displays immediately without server call.

Browser support

Here is when data-* support started for each browser:

1.0 Sep 2008
1.0 Sep 2002
1.0 Aug 1995
1.0 Jan 2006
1.0 Jan 2003

You may also like

 Back to <iframe>