Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <main class="[ container ] [ flow ]">
  <h1>Buy this thing!</h1>
  <p>It is very good and there's absolutely no hidden exceptions!</p>
  <a href="//" class="button">Buy it now!!</a>
  <div class="terms">
    <disclosure-toggle button-label="See the terms and conditions" class="flow">
      <p>Here's some secret terms and conditions that we didn't want you to see because they explain how the product isn't actually very good. </p>
        Lorem ipsum dolor sit amet, appareat pertinax et ius, ne pro nibh consulatu consetetur, nulla virtute definitiones nec in. Ad consul feugait eligendi mea, mutat tamquam ei mei. No hinc graecis phaedrum pro, cu erat ipsum sed, ut novum dissentiunt
        ullamcorper pro. <a href="#">Dicat aliquid dissentias</a> in per, meis alterum quaestio mei eu, vero praesent ex eam. Ei nam homero noluisse dissentiunt, ut vim quot putent. Vis elitr accusam accommodare id, cu usu quaestio conceptam, habeo tibique placerat eos
        cu. An nullam corpora consulatu qui, graeci euripidis est et.
        In tantas scripta nominati quo, ne essent maluisset voluptaria nam. Dicat putent feugiat ei sed, te vis delicata gubergren honestatis, ius liber blandit delicata ut. Vix et dictas detracto voluptua, vis an inani dicunt. Qui inciderint intellegebat ea,
        cetero verear cu duo.
        Vix id etiam sapientem. Vix case velit feugait eu. Id diceret delenit perpetua vis, has sale utamur aeterno te. Cum et consetetur mediocritatem.


                /* General presentation styles */

html {
  background: #212d40;

.link-button {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";

body {
  padding: 1.5rem;
  line-height: 1.4;
  color: #f3f3f3;

p {
  margin: 0;

article > * + * {
  margin-top: 1.5em;

a:not([class]) {
  color: currentcolor;

a:not([class]):focus {
  text-decoration: none;

.container {
  max-width: 30rem;
  margin: 0 auto;

.terms {
  --flow-space: 2rem;

/* Flow utility, which I write about here: */
.flow {
  --flow-space: 1em;

.flow > * + * {
  margin-top: var(--flow-space);

/* Button component */
.button {
  display: inline-block;
  border: none;
  padding: 0.6rem 1.2rem 0.8rem 1.2rem;
  text-decoration: none;
  background: #98b06f;
  color: #212d40;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  transition: background 250ms ease-in-out, transform 150ms ease;
  -webkit-appearance: none;
  -moz-appearance: none;

.button:focus {
  background: #ffffff;

.button:focus {
  outline: 1px solid #212d40;
  outline-offset: -4px;

.button:active {
  transform: scale(0.99);



class DisclosureToggle extends HTMLElement {
  constructor() {
    // Creates a shadow root for our slot etc
    this.root = this.attachShadow({mode: 'open'});
    // A key for setting the CSS Custom Property
    this.maxHeightKey = '--panel-max-height';
    // Create some component-level state
    this.state = {
      triggerExpanded: 'collapsed'
  // Render the component's markup and grab interactive elements
  connectedCallback() {
    this.root.innerHTML = this.render();
    this.trigger = this.root.querySelector('.js-trigger');
    this.panel = this.root.querySelector('.js-panel');
    this.panelInner = this.root.querySelector('.js-panel__inner');
    // Now the elements are grabbed, we can bind events and trigger the runner
    this.trigger.addEventListener('click', () =>;;
  // Looks for content within the panel and calculates its height. This makes the transition smoother.
  // Returns a promise so it can do its job before the toggle starts
  setMaxHeight() {
    const self = this;
    return new Promise((resolve, reject) => {
      if(!self.panel || !self.panelInner) {
      }, `${self.panelInner.getBoundingClientRect().height}px`);
  // Sets the relevant aria role based on its current value. Sets it to false by default
  // if no value is set
  setTriggerState() {
    let currentExpandedState = this.trigger.getAttribute('aria-expanded');

    // If it's not set yet, set it to true so it is reversed below
    if(currentExpandedState === null) {
      currentExpandedState = 'true';

    // Update our global state so other functions know what's up
    this.state.triggerExpanded = currentExpandedState === 'true' ? 'false' : 'true'

    this.trigger.setAttribute('aria-expanded', this.state.triggerExpanded);
  // A handy runner that is called from multiple places
  run() {
      .then(() => this.setTriggerState());
  // Getters are great and we use them to create a nice variable
  // for our button label text with a fallback
  get buttonLabel() {
    return this.getAttribute('button-label') || 'Toggle content';
  render() {
    return `
      hr {
        border: none;
        border-top: 1px dashed #ccc;
        margin: 1.5rem 0;

      .link-button {
        display: inline-flex;
        align-items: center;
        text-decoration: underline;
        text-decoration-skip-ink: auto;
        background: transparent;
        padding: 0;
        margin: 0;
        border: 0;
        color: #98b06f;
        font-size: 1rem;
        cursor: pointer;
        -webkit-appearance: none;
        -moz-appearance: none;

      .link-button svg {
        opacity: 0.8;
        margin-left: 0.5rem;
        transition: all 250ms ease-in-out;
        font-size: 0.8rem;

      .link-button[aria-expanded="true"] svg {
        transform: rotate(-180deg);

      .link-button:focus {
        text-decoration: none;

      .link-button:focus {
        text-decoration: none;
        outline: 1px solid rgba(255, 255, 255, 0.4);
        outline-offset: 0.6rem;

      .link-button:active {
        transform: scale(0.99);

      .panel {
        --panel-max-height: 500px;

        transition: all 200ms ease;
        position: relative;
        overflow-y: auto;
        overflow-x: hidden;
        visibility: hidden;
        max-height: 0;
        -webkit-overflow-scrolling: touch;

      .panel__inner {
        transition: all 500ms ease;
        transition-delay: 50ms;
        opacity: 0;
        transform: translateY(1rem);
        padding-top: 1.5rem;

      [aria-expanded="true"] + .panel {
        max-height: var(--panel-max-height);
        visibility: visible;

      [aria-expanded="true"] + .panel .panel__inner {
        opacity: 1;
        transform: translateY(0);
    <button class="[ link-button ] [ js-trigger ]" type="button">
      <svg viewBox="0 0 512 512" aria-hidden="true" fill="currentColor" width="1em" height="1em">
        <path d="M60 99.333l196 196 196-196 60 60-256 256-256-256z"></path>
    <div class="[ panel ] [ js-panel ]">
      <article class="[ panel__inner ] [ js-panel__inner ]">

if ('customElements' in window) {
  customElements.define('disclosure-toggle', DisclosureToggle);