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

              
                <main class='interface'>
  <div class='interface-top'>
    <input type='text' class='interface-input' placeholder='Press enter or add a comma after each tag'>
    <ion-icon class='interface-btn' name="pricetag-outline"></ion-icon>
  </div>
  <div class='interface-bottom'>
    <ul class='interface-list'></ul>
    <div class='interface-footer'>
      <p class='interface-remaining'>10 tags remaining</p>
      <button class='interface-clear'>clear all</button>
    </div>
  </div>
</main>

<script type="module" src="https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.esm.js"></script>
<script nomodule src="https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.js"></script>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  height: 100vh;
  display: grid;
  place-items: center;
}

.interface *, ::placeholder { font: 100 0.75rem 'myriad pro',helvetica,sans-serif; }

.interface {
  width: min(375px,90vw);
  border: 1.5px solid black;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.interface-top {
  display: flex;
  gap: 0.75rem;
}

.interface-input {
  flex: 1;
  padding: 0.5rem 1rem;
  border: 1px solid rgba(0,0,0,0.9);
  outline: none;
}

.interface-input:focus { border-color: rgba(0,0,0,0.25); }

::placeholder { color: rgba(0,0,0,0.3); }

.interface-btn {
  border: 1px solid rgba(0,0,0,0.9);
  font-size: 1rem;
  padding: 0.5rem;
  cursor: pointer;
}

.interface-btn:active {
  background-color: black;
  color: white;
}

.interface-bottom {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  display: none;
}

.interface-list {
  list-style-type: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  border: 0.25px solid rgba(0,0,0,0.25);
  padding: 1rem;
}

.interface-tag {
  color: rgba(0,0,0,0.6);
  border: 0.5px solid rgba(0,0,0,0.75);
  padding: 0.35rem 0.75rem;
  display: flex;
  gap: 0.75rem;
}

.interface-close {
  cursor: pointer;
  color: rgba(0,0,0,0.65);
}

.interface-close:active { color: rgba(0,0,0,0.5); }

.interface-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.interface-remaining {
  margin-left: 1rem;
}

.interface-clear {
  color: white;
  background-color: black;
  border: 1.5px solid black;
  outline: none;
  padding: 0.5rem 1rem;
  cursor: pointer;
}

.interface-clear:active {
  border: 1.5px solid black;
  background-color: transparent;
  color: black;
}

.active { display: flex; }  
              
            
!

JS

              
                const input = document.querySelector('.interface-input');
const bottom = document.querySelector('.interface-bottom');
const list = document.querySelector('.interface-list');
const remaining = document.querySelector('.interface-remaining');
const limit = 10;

const totalTags = () => list.querySelectorAll('.interface-tag').length;

function overLimit() {
  input.value = '';   
  input.placeholder = totalTags() >= limit
    ? `You've reached the limit of 10 tags`
    : `Press enter or add a comma after each tag`;
}

function closeTag(e) {
  e.target.parentElement.remove();
  remaining.textContent = `${limit - totalTags()} tags remaining`
  totalTags() === 0 && clearTags();
  overLimit();
}

function clearTags() {
  list.innerHTML = ''; 
  input.value = '';
  remaining.textContent = '10 tags remaining';
  setTimeout(() => bottom.classList.remove('active'),500);
}

function showTags() {
  if (!input.value.length) return;
  bottom.classList.add('active');
  list.innerHTML += createMarkup();
  input.value = '';
  remaining.textContent = `${limit - totalTags()} tags remaining`;
}

const isEnter = (e) => e.keyCode === 13 && showTags();

function createMarkup() {
  const tags = input.value.split(/[, ]/);
  const markup = [];
  if (totalTags() >= limit || !tags[0].length) overLimit();
  for (let i = 0; i < limit - totalTags(); i++) {
    if (!tags[i]) continue;
    markup.push(`
      <li class='interface-tag'>
        <span class='interface-tagName'>${tags[i]}</span>
        <span class='interface-close'>x</span>
      </li>
    `);
  }
  return markup.join('');
}

function init(e) {
  e.target.matches('.interface-clear') && clearTags();
  e.target.matches('.interface-close') && closeTag(e);
  e.target.matches('.interface-btn') && showTags();
}

input.addEventListener('input',createMarkup,false);
input.addEventListener('keydown',isEnter,false);
document.addEventListener('click',init,false);
              
            
!
999px

Console