Need private packages and team management tools?Check out npm Teams »


0.1.1 • Public • Published

Details Element Polyfill


travis build codecov coverage semantic-release version

The <details> element specifies additional details that the user can view or hide on demand. The <summary> element defines a visible heading for the <details> element. The heading can be clicked to show/hide the details.

The <details> element currently has very limited cross-browser support. This polyfill provides support for the <details> element across all modern browsers.

The polyfill is based on the spec for the details element.

If you'd like to use the details element and don't know where to start, take a look at this tutorial The details and summary elements at the html5doctor, read the tests or clone this repo and try out the demo.


  • keyboard and ARIA-friendly
  • fires click event when open state changes
  • fully customisable via CSS


$ npm install --save lavu-details-polyfill


Use it in your page

<script type="text/javascript" 

... or require the polyfill

var polyfillDetails = require('lavu-details-polyfill');

... or import the polyfill

import { polyfillDetails } from 'lavu-details-polyfill';

Start using it

<details role="group">
  <summary role="button">Show/Hide me</summary>
    <p>Some content.</p>

The script uses the load event to polyfill the <details> elements.

If you load HTML fragments dynamically, e.g. in a single page application, then you must call the polyfill after loading the HTML.


Where content is the parent node of the loaded HTML fragment.


The polyfill provides a minimal CSS meant to mimic the default unstyled browser look which you can override in your own CSS/SASS/LESS module. Code that overrides the default CSS is provided in the snippets example.

details, details>summary {
  display: block;
details > summary {
  min-height: 1.4em;
  padding: 0.125em;
details > summary:before {
  font-size: 1em;
  position: relative;
  display: inline-block;
  width: 1em;
  height: 1em;
  margin-right: 0.3em;
  -webkit-transform-origin: 0.4em 0.6em;
     -moz-transform-origin: 0.4em 0.6em;
      -ms-transform-origin: 0.4em 0.6em;
          transform-origin: 0.4em 0.6em;
details[open] > summary:before {
details > *:not(summary) {
  display: none;
  opacity: 0;
details[open] > *:not(summary) {
  display: block;
  opacity: 1;

The polyfill does not preserve the child elements layout when toggeling the details. Also, there is no guarantee that a browser's native implementation of the <details> element will respect it's child elements layout when toggeling the details. To preserve the child elements layout, you should always wrap the child elements inside a block element, e.g. <div>, <article>, <section> etc.

  .inline-element { display : inline-block; }
<details role="group">
  <summary role="button">Show/Hide me</summary>
    <div class="inline-element">
      <p>Some content ..... etc.</p>

Credits: The <details> polyfill is partly based on/inspired by the following sources:


MIT Licence 2016 © Leif Olsen


npm i lavu-details-polyfill

DownloadsWeekly Downloads






Last publish


  • avatar