Dofactory.com
Dofactory.com
Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

HTML <summary> id Attribute

An id on a <summary> tag assigns an identifier to the element.

The identifier must be unique across the page.

Example

#

An id attribute on a <summary> tag.

Order 4A801

You sold 125 shares of MSFT at 11:29 AM

You bought 200 shares of GOOG at 11:26 AM

<details>
  <summary id="trade-summary">Order 4A801</summary>
  <p>You sold 125 shares of MSFT at 11:29 AM</p>
  <p>You bought 200 shares of GOOG at 11:26 AM</p>
</details> 

Using id

The id attribute assigns an identifier to the <summary> element.

The id allows JavaScript to easily access the <summary> element.

It is also used to point to a specific id selector in a style sheet.

Tip:  id is a global attribute that can be applied to any HTML element.


Syntax

<summary id="identifier" />

Values

#

Value Description
identifier A unique alphanumeric string. The id value must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.).

More Examples

A <summary> element with a unique id attribute.
Clicking the button displays the content of the element.

Order 4A801

You sold 125 shares of MSFT at 11:29 AM

You bought 200 shares of GOOG at 11:26 AM


<details>
  <summary id="mysummary">Order 4A801</summary>
  <p>You sold 125 shares of MSFT at 11:29 AM</p>
  <p>You bought 200 shares of GOOG at 11:26 AM</p>
</details> 
  
<br />
<button onclick="show();">Show summary content</button>

<script>
  let show = () => {
     let element = document.getElementById("mysummary");
     alert("Content = " + element.innerHTML);
  }
</script>

Code explanation

The id attribute assigns a unique identifier for the <summary>.

Clicking the button calls JavaScript which locates the <summary> through the id.

Finally, the content of the <summary> is displayed in an alert box.


Browser support

Here is when id support started for each browser:

Chrome
12.0 Jun 2011
Firefox
48.0 Aug 2016
IE/Edge
Not supported
Opera
15.0 May 2013
Safari
6.0 Jul 2012

You may also like

 Back to <summary>

Last updated on Sep 30, 2023

Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

Guides