Tag Chip Input
Type and Enter creates removable chips
designvanilla
How to use it
- Paste the HTML where the forms & inputs should appear.
- Add the CSS to your stylesheet. All classes are prefixed, so nothing clashes with your own styles.
- Add the JavaScript and call init() with the element that contains the HTML.
<!-- Tag Chip Input · NedDev · eigen werk. -->
<div class="jouw-container">
<div class="tci-wrap"><span class="tci-chip">design<button class="tci-x" aria-label="verwijder">×</button></span><span class="tci-chip">vanilla<button class="tci-x" aria-label="verwijder">×</button></span><input class="tci-input" type="text" placeholder="Tag + Enter"></div>
</div>/* Tag Chip Input · NedDev · eigen werk. */
.tci-wrap{display:flex;flex-wrap:wrap;gap:7px;align-items:center;width:320px;box-sizing:border-box;padding:9px;background:#fff;border:1px solid rgba(10,10,10,.12);border-radius:12px;font-family:'Switzer',sans-serif;transition:border-color .2s}
.tci-wrap:focus-within{border-color:#F5480F}
.tci-chip{display:inline-flex;align-items:center;gap:5px;background:#0a0a0a;color:#fff;font-size:13px;padding:5px 6px 5px 11px;border-radius:20px;animation:tci-pop .2s ease}
@keyframes tci-pop{from{transform:scale(.6);opacity:0}to{transform:scale(1);opacity:1}}
.tci-x{border:none;background:rgba(255,255,255,.2);color:#fff;width:18px;height:18px;border-radius:50%;cursor:pointer;font-size:14px;line-height:1;display:flex;align-items:center;justify-content:center;transition:background .15s}
.tci-x:hover{background:#F5480F}
.tci-input{flex:1;min-width:80px;border:none;outline:none;font-size:14px;color:#0a0a0a;background:transparent;padding:5px}// Tag Chip Input · NedDev · eigen werk.
// root = het element waarin de HTML staat
function init(root){
root=root.querySelector('.tci-wrap')||root;var inp=root.querySelector('.tci-input');function bind(x){x.addEventListener('click',function(){x.parentNode.remove();});}[].forEach.call(root.querySelectorAll('.tci-x'),bind);inp.addEventListener('keydown',function(e){if(e.key==='Enter'&&inp.value.trim()){e.preventDefault();var c=document.createElement('span');c.className='tci-chip';c.textContent=inp.value.trim();var b=document.createElement('button');b.className='tci-x';b.setAttribute('aria-label','verwijder');b.innerHTML='×';bind(b);c.appendChild(b);root.insertBefore(c,inp);inp.value='';}else if(e.key==='Backspace'&&!inp.value){var chips=root.querySelectorAll('.tci-chip');if(chips.length)chips[chips.length-1].remove();}});
}
init(document.querySelector('.jouw-container'));
More forms & inputs
Seen something you like?
Add it to your selection and send it over. We build your site around it, in your brand.
Get in touch →