HTML <blockquote> data-* Attribute

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

Example

#

A custom data-speaker attribute on a <blockquote> tag.
The attribute value is not visible, but is readable by JavaScript.

And so, my fellow Americans: ask not what your country can do for you – ask what you can do for your country. My fellow citizens of the world: ask not what America will do for you, but what together we can do for the freedom of man.
-- President Kennedy, 1961, Inaugural address
<acticle>
  <blockquote data-speaker="John F. Kennedy">
    And so, my fellow Americans: ask not what your country 
    can do for you – ask what you can do for your country. 
    My fellow citizens of the world: ask not what America 
    will do for you, but what together we can do for the 
    freedom of man.
  </blockquote> 

  -- President Kennedy, 1961, Inaugural address
</article>

Using data-*

The data-* attribute adds custom information to a <blockquote> element.

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

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

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

Note: The data-* attribute is not visible and does not change the appearance of the blockquote.


Syntax

<blockquote data-*="value">

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


Values

#

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

More Examples

A custom data-location attribute on a <blockquote> tag.
Clicking the button will display the location value.

And so, my fellow Americans: ask not what your country can do for you – ask what you can do for your country. My fellow citizens of the world: ask not what America will do for you, but what together we can do for the freedom of man.
-- President Kennedy, 1961, Inaugural address.


<article>
  <blockquote data-location="Washington, DC" id="kennedyquote">
     And so, my fellow Americans: ask not what your country 
     can do for you – ask what you can do for your country. 
     My fellow citizens of the world: ask not what America 
     will do for you, but what together we can do for the 
     freedom of man.
  </blockquote> 

  -- President Kennedy, 1961, Inaugural address.
</article>

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

<script>
  let show = () => {
     let element = document.getElementById("kennedyquote");
     alert("Location = " + element.getAttribute('data-location'));
  }
</script>

Code explanation

The <blockquote> tag below contains the data-location attribute.

The data-location attribute specifies the location where the speach was delivered.

Clicks are handled by the onclick event.

Onclick invokes a JavaScript function that extracts and displays the location of the quotation.

Note: Notice that the location displays quickly without server call delay.


Browser support

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

Chrome
1.0 Sep 2008
Firefox
1.0 Sep 2002
IE/Edge
1.0 Aug 1995
Opera
1.0 Jan 2006
Safari
1.0 Jan 2003

You may also like

 Back to <blockquote>
Guides