HTML <summary> style Attribute

The style attribute on a <summary> tag assigns a unique style to the summary element. A style contains one or more CSS property/value pairs that define the appearance of the summary element.

Example

#

A style attribute on 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

<details>
  <summary style="background: #edf2ff; padding: 15px; outline: none; 
                  border-radius: 50px;">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 style

The style attribute specifies the style, i.e. look and feel, of the <summary> element.

A style contains any number of CSS property/value pairs, separated by semicolons (;).

The style attribute overrides any other style that was defined in a <style> tag or an external CSS file.

This inline styling affects the current <summary> element only.


Syntax

<summary style="CSS-styles">

Values

#

Value Description
CSS-styles One or more CSS property/value pairs separated by semicolons (;).

More Examples

A style attribute on a <summary> element.
Clicking the button toggles the background color.

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"
           style="background: lightblue; outline: none;padding: 15px; 
                  border-radius: 50px;">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 style</button>

<script>
  let toggle = () => {
     let element = document.getElementById("mysummary");

     if (element.style.backgroundColor === "lightblue") {
       element.style.backgroundColor = "lavender";
    } else {
       element.style.backgroundColor = "lightblue";
    }
  }
</script>

Code explanation

The style attribute assigns a background color to the <summary> element.

Clicking the button calls JavaScript which toggles the background to another color.


Browser support

Here is when style 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