Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

HTML

              
                //- inspiration = https://isotope.metafizzy.co
- 
  const elements = [
    { name: "Nitrogen", abbr: "N", float: "14.007", index: "7", tags: "" },
    { name: "Sodium", abbr: "Na", float: "22.99", index: "11", tags: "metal ium" },
    { name: "Argon", abbr: "Ar", float: "39.948", index: "18", tags: "" },
    { name: "Potassium", abbr: "K", float: "39.0983", index: "19", tags: "metal ium" },
    { name: "Calcium", abbr: "Ca", float: "40.078", index: "20", tags: "metal ium" },
    { name: "Cobalt", abbr: "Co", float: "58.933", index: "27", tags: "metal transition" },
    { name: "Cadmium", abbr: "Cd", float: "112.411", index: "48", tags: "metal transition ium" },
    { name: "Antimony", abbr: "Sb", float: "121.76", index: "51", tags: "" },
    { name: "Tellurium", abbr: "Te", float: "127.6", index: "52", tags: "ium" },
    { name: "Ytterbium", abbr: "Yb", float: "173.054", index: "70", tags: "metal ium" },
    { name: "Rhenium", abbr: "Re", float: "186.207", index: "75", tags: "metal transition ium" },
    { name: "Gold", abbr: "Au", float: "196.967", index: "79", tags: "metal transition" },
    { name: "Mercury", abbr: "Hg", float: "200.59", index: "80", tags: "metal transition" },
    { name: "Thallium", abbr: "Tl", float: "204.383", index: "81", tags: "metal ium" },
    { name: "Lead", abbr: "Pb", float: "207.2", index: "82", tags: "metal" },
    { name: "Bismuth", abbr: "Bi", float: "208.980", index: "83", tags: "metal" },
    { name: "Uranium", abbr: "U", float: "238.029", index: "92", tags: "metal ium" },
    { name: "Plutonium", abbr: "Pu", float: "244", index: "94", tags: "metal ium" },
  ].sort((a, b) => a.name.localeCompare(b.name))

.controls
  fieldset#filterelements
    legend Filter
    label
      input(type="radio" name="filter" value="all" checked)
      | show all
    label
      input(type="radio" name="filter" value="metal")
      | metal
    label
      input(type="radio" name="filter" value="transition")
      | transition
    label
      input(type="radio" name="filter" value="ium")
      | -ium

  fieldset#sortelements
    legend Sort
    label
      input(type="radio" name="sort" value="name" checked)
      | name
    label
      input(type="radio" name="sort" value="symbol")
      | symbol
    label
      input(type="radio" name="sort" value="number")
      | number

.container
  each element, i in elements
    .box(style=`--pos: ${i};` class=`${element.tags} box-${i}`)
      style.
        @media (prefers-reduced-motion: no-preference) {
          .box-#{i} {
            view-transition-name: box-#{i};
          }
        
          /* :only-child here makes the animation only fire if there's no pair for it */
          ::view-transition-old(box-#{i}):only-child {
            animation: scale-out .25s ease-out forwards;
          }

          ::view-transition-new(box-#{i}):only-child {
            opacity: 0;
            animation: 
              fade-in .01s ease-in forwards,
              scale-out .4s ease-in reverse;
          }
        }
          
        ::view-transition-group(box-#{i}) {
          animation-delay: #{i * 20}ms;
        }
      .number= element.index
      .symbol= element.abbr
      .name= element.name
      .float= element.float

              
            
!

CSS

              
                @keyframes scale-out {
  to { scale: 0 }
}

@keyframes fade-in {
  to { opacity: 1 }
}

@media (prefers-reduced-motion: no-preference) {
  ::view-transition-group(*) {
    animation-duration: 1.3s;
    animation-timing-function: linear(
      0, 0.009, 0.035 2.1%, 0.141, 0.281 6.7%, 0.723 12.9%, 0.938 16.7%, 1.017,
      1.077, 1.121, 1.149 24.3%, 1.159, 1.163, 1.161, 1.154 29.9%, 1.129 32.8%,
      1.051 39.6%, 1.017 43.1%, 0.991, 0.977 51%, 0.974 53.8%, 0.975 57.1%,
      0.997 69.8%, 1.003 76.9%, 1.004 83.8%, 1
    );
  }
}

@layer demo {
  .box {
    --hue: calc(var(--pos) * 20);
    background: oklch(65% .3 var(--hue));
    color: oklch(10% .3 var(--hue));
  }
  
  /*  
    further view-transition CSS is 
    inline with the pug templates so staggering
    and individual customizations can be done easier
  */
  
  html {
    /* optimization: */
    /* tell page you arent transitioning the whole page */
    view-transition-name: none;
  }
  
  /* allow interrupting the view transition with mouse */
  ::view-transition {
    pointer-events: none;
  }
}

@layer demo.support {
  * {
    box-sizing: border-box;
    margin: 0;
  }

  html {
    block-size: 100%;
    color-scheme: dark light;
  }

  body {
    min-block-size: 100%;
    font-family: system-ui, sans-serif;

    display: grid;
    align-content: start;
    padding: 1rem;
    gap: 1rem;
  }
  
  .number {
    text-align: end;
  }
  
  .symbol {
    color: Canvas;
    font-size: 60cqi;
    font-weight: bolder;
  }
  
  .float {
    font-size: .75em;
  }
  
  .container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(15ch, 1fr));
    gap: 2ch;
  }
  
  .box {
    container-type: inline-size;
    display: grid;
    align-content: space-between;
    aspect-ratio: 1;
    padding: 1rem;
    font-size: 1.25rem;
  }
  
  .controls {
    display: flex;
    flex-wrap: wrap;
    gap: 2rem 6rem;
  }
  
  fieldset {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 2ch;
    max-inline-size: max-content;
    border: none;
    padding: 0;
  }
  
  legend {
    padding: 0;
    font-weight: bolder;
    margin-block-end: .5ch;
  }
  
  label {
    display: flex;
    align-items: center;
    gap: .5ch;
    text-transform: capitalize;
  }
  
  label:has(:checked) {
    color: Highlight;
    color: AccentColor;
    text-decoration: underline Highlight;
  }
  
  @media (prefers-color-scheme: light) {
    label:has(:checked) {
      color: LinkText;
      color: AccentColor;
    }
  }
}
              
            
!

JS

              
                const boxes = document.querySelectorAll('.box')

window.filterelements.oninput = e => {
  e.target.value === 'all'
    ? viewTransition(showAll) 
    : viewTransition(filterBy, e.target.value)
}

window.sortelements.oninput = e => {
  viewTransition(sortBy, e.target.value)
}

function viewTransition(fn, params) {
  if (document?.startViewTransition) {
    document.startViewTransition(() => {
      fn(params)
    })
  }
  else fn(params)
}

function showAll() {
  boxes.forEach(box => box.style.display = null)
}

function filterBy(classname) {
  boxes.forEach(box =>
    box.style.display = box.classList.contains(classname) ? null : 'none')
}

function sortBy(classname) {
  const parent = boxes[0].parentNode
  parent.innerHTML = ''

  Array.from(boxes).sort((a, b) => {
    const nameA = a.querySelector(`.${classname}`).innerText
    const nameB = b.querySelector(`.${classname}`).innerText
    return nameA.localeCompare(nameB)
  }).forEach(box => {
    parent.appendChild(box)
  })
}

// animating display: none || block
function modifyDom() {
  document.querySelectorAll('.box').forEach(box => {
    box.style.display = Math.random() >= .5 ? null : 'none'
  })
}
              
            
!
999px

Console