HTML <summary> class Attribute

The class attribute on a <summary> tag assigns one or more classnames to the summary element. Classes are used to style elements. Classnames are defined in a stylesheet or in a local <style> element.

Example

#

A class attribute styling a <summary> element.

Order 4A801

You sold 125 shares of MSFT at 11:29 AM

You bought 200 shares of GOOG at 11:26 AM

<style>
  .summary {
    background: #edf2ff; outline: none;
    padding: 15px; border-radius: 5px;
    text-transform: uppercase;
  }
</style>

<details>
  <summary class="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 class

The class attribute assigns one or more classnames to the <summary> tag.

Multiple classnames are separated by a space.

Classes (i.e. classnames) are used for styling the summary element.

JavaScript uses classes to access one or more elements by classname.

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


Syntax

<summary class="classnames">

Values

#

Value Description
classnames One or more space-separated class names.

More Examples

A class attribute styling a <summary> element.
Clicking the button toggles a classname that changes the background and text colors.

Order 4A801

You sold 125 shares of MSFT at 11:29 AM

You bought 200 shares of GOOG at 11:26 AM


<style>
  .summary-light {
    background: #edf2ff; outline: none;
    padding: 15px; border-radius: 5px;
    text-transform: uppercase;
  }
  .summary-dark { background: #3630a3; color: white; }
</style>

<details>
  <summary id="mysummary" class="summary-light">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="toggle();">Toggle class</button>

<script>
  let toggle = () => {
     let element = document.getElementById("mysummary");
     element.classList.toggle("summary-dark");
  }
</script>

Code explanation

Two CSS classes are defined in the <style> element.

The class attribute in <summary> assigns one classname.

Repeatedly clicking the button toggles the second class, changing the background and text color of the <summary>.


Browser support

Here is when class 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>
Guides