data

The data attribute in HTML, used with the <object> tag, enables the embedding of external resources that can be accessed via JavaScript or other scripts.

data attribute

The data attribute in HTML is used to store custom data associated with an element. It allows developers to embed extra information that can be accessed and manipulated using JavaScript or other scripting languages.

Syntax

index.html
<object data="URL">

Example

Here’s an example of using the data attribute in HTML:

Example

index.html
<object data="images/earth.mp4" type="video/mp4"></object>

Definition and Usage

The data attribute allows you to store custom data specific to a page or application.

It lets you embed custom data attributes in any HTML element.

This data can then be accessed via JavaScript to enhance the user experience without the need for Ajax calls or server-side queries.

Custom attributes starting with "data-" are ignored by the user agent.

Values

  • URL
    • A URL that indicates the location of the object's data.

Applies To

The data attribute can be applied to the following HTML elements.

Conclusion

The data attribute in HTML allows developers to embed external resources within elements, accessible through JavaScript or other scripts. It helps store custom data for a page or application, enhancing interactivity. This attribute is primarily used with the <object> element.