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

              
                <h3>Automatically Paged Carousel - toggleable inert</h3>
<p>This is an example of how a paged carousel could be automatically created with columns. The items are each individually focusable. There are focusable divs before and after the scroller to test focus order</p>
<input id=inert type=checkbox> Inert offscreen items<br>
<div class="wrapper">
  <ul class="carousel">
    <li tabindex=0></li>
    <li tabindex=0></li>
    <li tabindex=0></li>
    <li tabindex=0></li>
    <li tabindex=0></li>
    <li tabindex=0></li>
    <li tabindex=0></li>
    <li tabindex=0></li>
    <li tabindex=0></li>
    <li tabindex=0></li>
    <li tabindex=0></li>
    <li tabindex=0></li>
    <li tabindex=0></li>
    <li tabindex=0></li>
    <li tabindex=0></li>
    <li tabindex=0></li>
  </ul>
</div>
<div id="after-carousel" tabindex=0>Focusable item after carousel</div>
<div id="focused-element"></div>
              
            
!

CSS

              
                .wrapper {
  contain: layout;
  overflow: hidden;
  position: relative;
  resize: horizontal;
  width: 600px;
  height: 400px;
  border: 1px solid gray;
  overscroll-behavior: none;
}

:focus {
  outline: 2px solid blue;
}

#focused-element {
  cursor: pointer;
  position: fixed;
  bottom: 8px;
  right: 8px;
  background: rgba(255, 255, 255, 0.8);
  border: 2px solid gray;
  
  &:before {
    content: 'focused: '
  }
}

ul {
  /* Paginate */
  columns: 1;

  /* Scrolling behavior. */
  overflow: auto;
  overscroll-behavior: none;
  scroll-behavior: smooth;
  scrollbar-width: none;
  scroll-snap-type: x mandatory;
  
  /* Reset list styles */
  list-style-type: none;
  
  /* Styles and layout */
  box-sizing: border-box;
  padding: 10px;
  position: relative;
  width: 100%;
  height: calc(100% - 90px);
  scroll-padding: 10px;
  counter-reset: item page;
  text-align: center;
}

ul::column {
  scroll-snap-align: center;
}

ul li {
  display: inline-block;
  width: 180px;
  height: 285px;
  position: relative;
  background: #ddd;
  border: 1px solid #aaa;

  &:focus {
    outline: 2px solid blue;
  }

  /* Item label */
  &::before {
    position: absolute;
    bottom: 15px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: x-large;
    counter-increment: item;
    content: "Item " counter(item);
  }
}

/* Scroll marker area */
ul {
  scroll-marker-group: after;
}

ul::scroll-marker-group {
  height: 45px;
  width: 100%;
  display: block;
  scroll-behavior: smooth;
  overflow-y: hidden;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  text-align: center;
  white-space: nowrap;
}

/* Page markers */
ul::column::scroll-marker {
  content: ' ' / 'Page';
  display: inline-block;
  width: 35px;
  height: 35px;
  border: 3px solid gray;
  border-radius: 50%;
  margin: 3px;
  scroll-snap-align: center;
}

ul::column::scroll-marker:target-current {
  background: blue;
}

ul::column::scroll-marker:focus {
  outline: 2px solid blue;
  outline-offset: 2px;
}

/* Scroll buttons */
/* scroll-button(*) seems to be matching the ::scroll-marker-group?? */
ul::scroll-button(*) {
  position: fixed;
  cursor: pointer;
  font-size: 50px;
  line-height: 50px;
  text-align: center;
  z-index: 1;
  top: calc(50% - 25px);
}
ul::scroll-button(right) {
  right: 15px;
  content: '➡️' / 'Next page';
}
ul::scroll-button(left) {
  left: 15px;
  content: '⬅️' / 'Previous page';
}

@keyframes inert-out-of-view {
  0% { visibility: hidden; visibility: inert; }
  0.01% { visibility: visible; interactivity: auto; }
  99.99% { visibility: visible; interactivity: auto; }
  100% { visibility: hidden; visibility: inert; interactivity: inert; }
}

/* Conditionally inert inactive items */
body:has(#inert:checked) li {
  animation: inert-out-of-view both;
  animation-timeline: view(inline);
  animation-range: entry 50% exit 50%;
}

ul {
    /* Specify scroll-button:focus last so that a parsing error doesn't lose other styles: https://issues.chromium.org/issues/343979378 */
  &::scroll-button(right):focus, &::scroll-button(left):focus {
    outline: 2px solid blue;
  }
}
              
            
!

JS

              
                function elementSelector(elem) {
  const nth = (elem, selector) => {
  let matches = Array.prototype.slice.apply((elem.parentElement || document).querySelectorAll(`:scope > ${selector}`));
  if (matches.length == 1)
    return selector;
  let index = matches.indexOf(elem);
  return `${selector}:nth-of-type(${index + 1})`;
}
  const path = (elem, selector) => {
    if (document.querySelectorAll(selector).length == 1)
      return '';
    return `${elementSelector(elem.parentElement)} > `;
  }
  
  if (!elem) return ':root';
  if (elem.id)
    return `#${elem.id}`;
  let selector = '';
  if (elem.className) {
    selector = `.${elem.className.replace(' ', '.')}`;
  } else {
    selector = elem.tagName.toLowerCase();
  }
  return path(elem, selector) + nth(elem, selector);
}

const focusIndicator = document.getElementById('focused-element');
focusIndicator.addEventListener('mousedown', (evt) => {
  evt.preventDefault();
  navigator.clipboard.writeText(focusIndicator.textContent);
});
function updateFocus() {
  console.log(document.activeElement);
  focusIndicator.textContent = elementSelector(document.activeElement);
}

document.body.addEventListener('focusin', updateFocus);
document.body.addEventListener('focusout', updateFocus);

              
            
!
999px

Console