Pen Settings

HTML

CSS

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

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

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.

HTML

              
                <!-- value can be "name" or "email", while "email" 
is prefered becuase it's unique, unlike a name -->
<input name='tags' value='abatisse2@nih.gov, Justinian Hattersley'>
              
            
!

CSS

              
                body{
  justify-content: flex-start;
  padding-top: 10vh;
  font-family: 'Roboto', sans-serif;
}

.tagify{    
  width: 100%;
  max-width: 700px;
  background: rgba(white, .8);
}

/* Suggestions items */
.tagify__dropdown.users-list {
  $avatar-size: 36px;
  
  font-size: 14px;
  
  .tagify__dropdown__item{
      padding: .5em .7em;
      display: grid;
      grid-template-columns: auto 1fr;
      gap: 0 1em;
      grid-template-areas: "avatar name"
                           "avatar email";

      &:hover .tagify__dropdown__item__avatar-wrap{
          transform: scale(1.2);
      }
    
      &__avatar-wrap{
        grid-area: avatar;
        width: $avatar-size;
        height: $avatar-size;
        border-radius: 50%;
        overflow: hidden;
        background: #EEE;
        transition: .1s ease-out;
      }
  }

  img{
      width: 100%;
      vertical-align: top;
  }

  strong{
      grid-area: name;
      width: 100%;
      align-self: center;
      font-weight: 500;
  }

  span{
      grid-area: email;
      width: 100%;
      font-size: .9em;
      opacity: .6;
  }

  .addAll{
      border-bottom: 1px solid #DDD;
      gap: 0;
  }
}


/* Tags items */
.tagify__tag{
    white-space: nowrap;

    &:hover .tagify__tag__avatar-wrap{
        transform: scale(1.6) translateX(-10%);
    }

    .tagify__tag__avatar-wrap{
        width: 16px;
        height: 16px;
        white-space: normal;
        background: silver;
        border-radius: 50%;
        margin-right: 5px;
        transition: .12s ease-out;
    }

    img{
        width: 100%;
        vertical-align: top;
    }
}
              
            
!

JS

              
                var inputElm = document.querySelector('input[name=tags]');

var usersList = [
    {
        "value": 1,
        "name": "Justinian Hattersley",
        "avatar": "https://i.pravatar.cc/80?img=1",
        "email": "jhattersley0@ucsd.edu"
    },
    {
        "value": 2,
        "name": "Antons Esson",
        "avatar": "https://i.pravatar.cc/80?img=2",
        "email": "aesson1@ning.com"
    },
    {
        "value": 3,
        "name": "Ardeen Batisse",
        "avatar": "https://i.pravatar.cc/80?img=3",
        "email": "abatisse2@nih.gov"
    },
    {
        "value": 4,
        "name": "Graeme Yellowley",
        "avatar": "https://i.pravatar.cc/80?img=4",
        "email": "gyellowley3@behance.net"
    },
    {
        "value": 5,
        "name": "Dido Wilford",
        "avatar": "https://i.pravatar.cc/80?img=5",
        "email": "dwilford4@jugem.jp"
    },
    {
        "value": 6,
        "name": "Celesta Orwin",
        "avatar": "https://i.pravatar.cc/80?img=6",
        "email": "corwin5@meetup.com"
    },
    {
        "value": 7,
        "name": "Sally Main",
        "avatar": "https://i.pravatar.cc/80?img=7",
        "email": "smain6@techcrunch.com"
    },
    {
        "value": 8,
        "name": "Grethel Haysman",
        "avatar": "https://i.pravatar.cc/80?img=8",
        "email": "ghaysman7@mashable.com"
    },
    {
        "value": 9,
        "name": "Marvin Mandrake",
        "avatar": "https://i.pravatar.cc/80?img=9",
        "email": "mmandrake8@sourceforge.net"
    },
    {
        "value": 10,
        "name": "Corrie Tidey",
        "avatar": "https://i.pravatar.cc/80?img=10",
        "email": "ctidey9@youtube.com"
    }
]

function tagTemplate(tagData){
    return `
        <tag title="${(tagData.title || tagData.email)}"
                contenteditable='false'
                spellcheck='false'
                tabIndex="-1"
                class="${this.settings.classNames.tag} ${tagData.class ? tagData.class : ""}"
                ${this.getAttributes(tagData)}>
            <x title='' class='tagify__tag__removeBtn' role='button' aria-label='remove tag'></x>
            <div>
                <div class='tagify__tag__avatar-wrap'>
                    <img onerror="this.style.visibility='hidden'" src="${tagData.avatar}">
                </div>
                <span class='tagify__tag-text'>${tagData.name}</span>
            </div>
        </tag>
    `
}

function suggestionItemTemplate(tagData){
    return `
        <div ${this.getAttributes(tagData)}
            class='tagify__dropdown__item ${tagData.class ? tagData.class : ""}'
            tabindex="0"
            role="option">
            ${ tagData.avatar ? `
            <div class='tagify__dropdown__item__avatar-wrap'>
                <img onerror="this.style.visibility='hidden'" src="${tagData.avatar}">
            </div>` : ''
            }
            <strong>${tagData.name}</strong>
            <span>${tagData.email}</span>
        </div>
    `
}

// initialize Tagify on the above input node reference
var tagify = new Tagify(inputElm, {
    tagTextProp: 'name', // very important since a custom template is used with this property as text. allows typing a "value" or a "name" to match input with whitelist
    enforceWhitelist: true,
    skipInvalid: true, // do not remporarily add invalid tags
    dropdown: {
        closeOnSelect: false,
        enabled: 0,
        classname: 'users-list',
        searchKeys: ['name', 'email']  // very important to set by which keys to search for suggesttions when typing
    },
    templates: {
        tag: tagTemplate,
        dropdownItem: suggestionItemTemplate
    },
    whitelist: usersList
})

tagify.on('dropdown:show dropdown:updated', onDropdownShow)
tagify.on('dropdown:select', onSelectSuggestion)

var addAllSuggestionsElm;

function onDropdownShow(e){
    var dropdownContentElm = e.detail.tagify.DOM.dropdown.content;

    if( tagify.suggestedListItems.length > 1 ){
        addAllSuggestionsElm = getAddAllSuggestionsElm();

        // insert "addAllSuggestionsElm" as the first element in the suggestions list
        dropdownContentElm.insertBefore(addAllSuggestionsElm, dropdownContentElm.firstChild)
    }
}

function onSelectSuggestion(e){
    if( e.detail.elm == addAllSuggestionsElm )
        tagify.dropdown.selectAll.call(tagify);
}

// create a "add all" custom suggestion element every time the dropdown changes
function getAddAllSuggestionsElm(){
    // suggestions items should be based on "dropdownItem" template
    return tagify.parseTemplate('dropdownItem', [{
            class: "addAll",
            name: "Add all",
            email: tagify.settings.whitelist.reduce(function(remainingSuggestions, item){
                return tagify.isTagDuplicate(item.value) ? remainingSuggestions : remainingSuggestions + 1
            }, 0) + " Members"
        }]
      )
}
              
            
!
999px

Console