8

I want to use the HTML5 summary element on Firefox. By default, the element is styled with a triangular arrow (see an example here). I want to change the color of this arrow. This question explains how this can be done for Chrome, but after testing it does not work for Firefox.

Is there a way to change the color of the arrow of the summary element with Firefox?

TylerH
  • 20,799
  • 66
  • 75
  • 101
a3nm
  • 8,717
  • 6
  • 31
  • 39

7 Answers7

14

Removing the caret in Firefox and Chrome:

details summary { list-style-type: none; } /* Firefox */
details summary::-webkit-details-marker { display: none; } /* Chrome */
details summary::marker { display: none; }
<details>
  <summary>Open/Close</summary>
  Lorem ipsum dolor sit.
</details>
dipser
  • 442
  • 3
  • 5
9

Currently on FF 68 I am able to customise the marker by doing:

summary::marker {
  color: red;
}

Make sure to try to apply the styles in a generic way (AKA avoid nesting classes so you are sure that the traverse is not a problem)

Screenshot of details marker customization

Also, as you probably are adding styles cross browser the below snippet doesn't work properly

summary::marker,
summary::-webkit-details-marker {
    color: $primary;
}

Instead I have to define it separately like so:

summary::marker {
  color: $primary;
}

summary::-webkit-details-marker {
  color: $primary;
}
Alexis Duran
  • 620
  • 14
  • 28
  • 2
    Thanks! I think that's the best answer currently -- no need for an additional `span`, no need to redefine the arrow manually. BTW, I guess the reason why you have to define separately is https://stackoverflow.com/questions/13816764/invalid-css-selector-causes-rule-to-be-dropped-what-is-the-rationale (because each of Firefox and Chrome won't understand the other's selector). – a3nm Aug 25 '19 at 15:42
2

You can use list-style-type in Firefox (and perhaps Edge/Safari) to style the arrow [css-tricks].

/* replace with custom image */
summary {
  list-style-image: url(right-arrow.svg);
}

/* hide arrow */
summary {
  list-style-image: none;
}
Paul Irish
  • 47,354
  • 22
  • 98
  • 132
1
/* Hide default arrow */     
summary::-moz-list-bullet {
   list-style-type: none;
   display: block;
}
/* Create customizable arrow */       
summary:before {
   content: ' ';
   border: solid #939faa;
   border-width: 0 2px 2px 0;
   display: inline-block;
   padding: 0 5px 5px 0;
   transform: rotate(-45deg);
}

http://www.otsukare.info/2016/04/19/summary-details

Kate
  • 19
  • 1
1

Gotcha: if you use normalizer (normalize.css etc.) or something similar, in order to hide the ::marker in Firefox in macOS, you have to style both <summary> and the ::marker:

  summary {
    display: block;
  }

  summary::marker {
    display: none;
  }

Otherwise <summary> will get its styles from elsewhere (normalizer etc.) and it could be something like display: list-item, which will prevent you from hiding the marker.

Neurotransmitter
  • 6,289
  • 2
  • 51
  • 38
0
details > summary:first-of-type {
    color: blue;
}

This CSS will work on Firefox, but you will still need to use the original method for Chrome.

TylerH
  • 20,799
  • 66
  • 75
  • 101
static_null
  • 194
  • 4
  • 14
  • 1
    Thanks, but this changes the color of the whole `summary` element (not just the arrow). That said, based on this, I guess I could style the `summary` element (with the arrow), and then put the actual contents of the `summary` element in a `span` that I would style differently. If you think that this is the best solution, feel free to edit your answer accordingly. – a3nm Aug 13 '18 at 22:26
0

A simple workaround to change the color of the summary arrow in Firefox is simply to change the color of the entire summary element, and put the contents of the element in a span styled in a different way.

For instance:

<style type="text/css">
summary {
  color: red;
}
.summary_contents {
  color: black;
}
</style>

And:

<details>
  <summary>
    <span class="summary_contents">foobar</span>
  </summary>
  [...]
</details>
a3nm
  • 8,717
  • 6
  • 31
  • 39