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

              
                <div class="container">  
  <h1>Examples</h1>
  <form action="" method="POST">
    <select name="select" id="select">
      <option value="Côte d'Ivoire">Côte d'Ivoire</option>
      <option value="Gibraltar" disabled>Gibraltar</option>
      <option value="Sudan">Sudan</option>
      <option value="Antigua & Barbuda">Antigua & Barbuda</option>
      <option value="South Korea">South Korea</option>
      <option value="Diego Garcia" disabled>Diego Garcia</option>
      <option value="France">France</option>
      <option value="Guadeloupe">Guadeloupe</option>
      <option value="Yemen">Yemen</option>
      <option value="Micronesia" disabled>Micronesia</option>
      <optgroup for="Option group">
        <option value="Lesotho">Lesotho</option>
        <option value="St. Martin" disabled>St. Martin</option>
        <option value="Kiribati">Kiribati</option>
      </optgroup>
      <option value="Lebanon" disabled>Lebanon</option>
      <option value="Jersey">Jersey</option>
      <option value="Netherlands" selected>Netherlands</option>
      <optgroup for="Disabled option group" disabled>
        <option value="Pakistan">Pakistan</option>
        <option value="Réunion">Réunion</option>
        <option value="Antarctica">Antarctica</option>
      </optgroup>
      <option value="Botswana">Botswana</option>
      <option value="Falkland Islands">Falkland Islands</option>
      <option value="Montenegro">Montenegro</option>
    </select>
    <input type="submit" value="Send" />
  </form>
</div>

<section>
  <div class="container">
    <h3>Change callback</h3>

    <select name="callback" id="select-callback">
      <option value="1" selected>One</option>
      <option value="2">Two</option>
      <option value="3">Three</option>
      <option value="4">Four</option>
      <option value="5">Five</option>
    </select>

    <pre><code class="language-javascript">new Select(el, {
  onChange: function(event, value, text, index) {
    alert('Event: ' + event.type + '\nYou choised (' + text + ')\nIndex(' + index + ')\nValue(' + value + ')')
  }
});</code></pre>

  </div>
</section>
<section>
  <div class="container">
    <h3>Show max items</h3>
    <select name="maxitems" id="select-maxitems">
      <option value="1" selected>One</option>
      <option value="2">Two</option>
      <option value="3">Three</option>
      <option value="4">Four</option>
      <option value="5">Five</option>
      <option value="6">Six</option>
      <option value="7">Seven</option>
    </select>

    <pre><code class="language-javascript">new Select(el, {
  showMaxOptions: 3
});</code></pre>
  </div>
</section>

<section>
  <div class="container">
    <h3>Max width</h3>
    <select name="maxwidth" id="select-maxwidth">
      <option value="1" selected>One</option>
      <option value="2">Two</option>
      <option value="3">Three</option>
      <option value="4">Four</option>
      <option value="5">Five</option>
      <option value="6">Six</option>
      <option value="7">Seven</option>
    </select>

    <pre><code class="language-javascript">new Select(el, {
  maxWidth: 350
});</code></pre>
  </div>
</section>

<section>
  <div class="container">

    <h3>Destroy</h3>
    <div class="form-group">
      <select name="maxwidth" id="select-destroy">
        <option value="1" selected>One</option>
        <option value="2">Two</option>
        <option value="3">Three</option>
        <option value="4">Four</option>
        <option value="5">Five</option>
        <option value="6">Six</option>
        <option value="7">Seven</option>
      </select>
    </div>
    <button id="toggle">destroy</button>

    <pre><code class="language-javascript">var select = new Select(el, {
  maxWidth: 350
});
// some time later
select.destroy();</code></pre>
  </div>

</section>

<section>
  <div class="container">

    <h3>New option</h3>
    <div class="form-group">
      <select name="maxwidth" id="select-add">
        <option value="1" selected>One</option>
        <option value="2">Two</option>
        <option value="3">Three</option>
        <option value="4">Four</option>
        <option value="5">Five</option>
        <option value="6">Six</option>
        <option value="7">Seven</option>
      </select>
    </div>
    <button id="addoption">add option</button>

    <pre><code class="language-javascript">var select = new Select(el, {
  maxWidth: 350
});
// Adding new option into system select
el.innerHTML += '&lt;option value="new_option"&gt;New option&lt;/option&gt;';
// update custom select
select.update();</code></pre>
  </div>
</section>

<section>
  <div class="container">

    <h3>Custom styles</h3>
    <div class="form-group">
      <select name="custom" id="custom">
        <option value="Gambia">Gambia</option>
        <option value="Moldova">Moldova</option>
        <option value="Turks &amp; Caicos Islands">Turks &amp; Caicos Islands</option>
        <option value="American Samoa">American Samoa</option>
        <option value="Haiti">Haiti</option>
        <option value="French Southern Territories">French Southern Territories</option>
        <option value="Iceland">Iceland</option>
      </select>
    </div>

    <pre><code class="language-javascript">var select = new Select(el, {
  customClass: 'custom' // for example
});</code></pre>
  </div>
</section>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Fira+Sans:400,600&subset=cyrillic');
@import url('https://fonts.googleapis.com/css?family=Fira+Mono|Fira+Sans&subset=cyrillic');

body {
  font-size: 1rem;
  font-family: -apple-system,system-ui,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",sans-serif;
  color: #555;
}

.container {
  width: 100%;
  max-width: 650px;
  margin-left: auto;
  margin-right: auto;
}

pre {
  margin-bottom: 1rem;
  padding: 0.5rem 1rem;
  line-height: 1.6;
  font-size: .85rem;
  tab-size: 4;
  font-family: 'Fira Mono', monospace;
  overflow: auto;
  color: #555;
  background-color: #f8f8f8;
}
pre > code {
  font-family: inherit;
  font-size: inherit;
}

code {
  font-family: 'Fira Mono', monospace;
  font-size: .8rem;
  background-color: #f8f8f8;
  padding: 0.3rem;
}

h1,h2,h3 {
  font-weight: 600;
}

.form-group {
  margin-bottom: 1rem;
}

section {
  padding: 1rem;
}

$select-icon: 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMSIgaGVpZ2h0PSI2Ij48cGF0aCBkPSJNMTAuMzEyIDBMNS41IDQuNjY2LjY4OCAwIDAgLjY2NyA1LjUgNiAxMSAuNjY3Ii8+PC9zdmc+';
$select-accent-color: #1e90ff;
$select-active-bg: $select-accent-color;
$select-bg: #fff;
$list-bg: #fff;
$select-padding: 7px 12px;
$select-hover-bg: #f1f1f1;
$select-hover-color: #555;
$select-active-color: #fff;

$select-border-width: 2px;
$list-border-width: 1px;

$select-border: $select-border-width solid #ddd;
$list-border: $list-border-width solid $select-accent-color;

select {
  min-width: 100px;
}

.cs {
  position: relative;
  display:inline-block;
  vertical-align:middle;
  max-width:inherit;
  min-width: 100px;
  outline: 0;

  * {
    box-sizing: border-box;
  }

  &-label {
    padding: $select-padding;
    padding-right: 20px;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: inherit;
    font-family: inherit;
    cursor: pointer;
    border: $select-border;
    overflow: hidden;
    user-select: none;

    &::after {
      content: '';
      position: absolute;
      right: 7px;
      top: 0;
      bottom: 0;
      width: 10px;
      height: 10px;
      margin: auto;
      z-index: 2;
      opacity: .7;
      background-image: url($select-icon);
      background-position: center;
      background-size: contain;
      background-repeat: no-repeat;
      transition: transform .3s;
    }
  }

  &-list {
    position: absolute;
    width: 100%;
    left: 0;
    right: 0;
    max-height: 200px;
    margin: 0;
    padding: 0;
    list-style: none;
    visibility: hidden;
    overflow-y:auto;
    overflow-x:hidden;
    border: $list-border;
    background: $list-bg;
    user-select: none;
    pointer-events: none;
    z-index: 3;
  }

  &-item {
    padding: $select-padding;
    font-size: inherit;
    font-family: inherit;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    cursor: pointer;

    &:hover {
      color: $select-hover-color;
      background-color: $select-hover-bg;
    }
    &--disabled {
      color: #9f9f9f;
      cursor: no-drop;
      &:hover {
        background-color: transparent;
        color: #9f9f9f;
      }
    }
    &--group {
      font-weight: 600;
    }
    &--group:not(&--disabled) {
      color: #555;
      cursor: default;
      &:hover {
        color: currentColor;
        background-color: transparent;
      }
    }
    &--groupchild {
      padding-left: 20px;
    }

    &.is-active {
      color: $select-active-color;
      background: $select-active-bg;
    }
  }

  &.is-open &-list {
    visibility: visible;
    pointer-events: all;
  }

  &.is-open &-label {
    &::after {
      transform:rotate(180deg)
    }
  }

  &:focus &-label,
  &.is-open &-label {
    border-color: $select-active-bg;
    box-shadow: 0 2px 10px rgba(#000, .15);
  }
}

/*-----animate-----*/
.slideInUp,
.zoomInDown,
.slideInDown,
.fadeIn {
  // transition: all .2s ease;
  transition-property: visibility, opacity, transform;
  transition-duration: .2s;
  transition-timing-function: ease;
}
.slideInUp {
  transform: translateY(10px);
  opacity: 0;
}
.is-open .slideInUp {
  visibility:visible;
  transform: translateY(0);
  opacity:1;
}
.slideInDown {
  transform: translateY(-10px);
  opacity: 0;
}
.is-open .slideInDown {
  visibility:visible;
  transform: translateY(0);
  opacity:1;
}
.fadeIn {
  transition-timing-function: linear;
  opacity:0;
}
.is-open .fadeIn {
  opacity: 1;
  visibility: visible;
}
.zoomInDown {
  transform-origin: 50% 0;
  opacity:0;
  transform: scale(.5) translateY(-10px);
}
.is-open .zoomInDown {
  transform: scale(1) translateY(0);
  visibility:visible;
  opacity:1;
}

.select-custom .cs-label {
  border-width: 1px;
  border-radius: 3px;
}
.select-custom .cs-label::after {
  width: 14px;
  height: 14px;
  background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdib3g9IjAgMCAyMCAyMCIgd2lkdGg9IjIwIiBoZWlnaHQ9IjIwIj48cGF0aCBkPSJNMTAgMWwtNSA3aDEwbC01LTd6TTEwIDE5bDUtN2gtMTBsNSA3eiI+PC9wYXRoPjwvc3ZnPg==);
  transform: none;
}
.select-custom.is-open .cs-label,
.select-custom:focus .cs-label {
  border-color: #c5c5c5;
}
.select-custom.is-open .cs-label {
  background: #f0f8ff;
}
.select-custom .cs-list {
  border-width: 1px;
  border-color: #c5c5c5;
}
.select-custom .above {
  margin-bottom: -2px;
}
.select-custom .below {
  margin-top: -2px;
}
.select-custom .cs-item:hover {
  background-color: #f1f1f1;
  color: #555;
}
.select-custom .cs-item.is-active,
.select-custom .cs-item:hover {
  background-color: #f1f1f1;
  color: #555;
}
.select-custom .cs-list::-webkit-scrollbar {
  width: 10px;
}
.select-custom .cs-list::-webkit-scrollbar-thumb {
  min-height: 35px;
  background-clip: padding-box;
  background-color: rgba(51, 51, 51, 0.3);
  border: 1px solid transparent;
  border-radius: 0;
}
.select-custom .cs-list::-webkit-scrollbar-thumb:hover {
  background-color: rgba(51, 51, 51, 0.75);
}

code[class*=language-],
pre[class*=language-] {
  font-family: Fira Mono, Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;
  font-size: .85rem;
  tab-size: 2;
}
              
            
!

JS

              
                var el = document.getElementById('select');
var s = new CSelect(el);
// Demo 1
new CSelect(document.getElementById('select-callback'), {
  onChange: function (event, value, text, index) {
    alert('Event: ' + event.type + '\nYou choised (' + text + ')\nIndex(' + index + ')\nValue(' + value + ')')
  }
});
// Demo 2
new CSelect(document.getElementById('select-maxitems'), {
  showMaxOptions: 3
});
// Demo 3
new CSelect(document.getElementById('select-maxwidth'), {
  maxWidth: 350
});
// Demo 4
var options = {
  maxWidth: 350,
  animation: 'zoomInDown'
}
var demo4 = new CSelect(document.getElementById('select-destroy'), options);
document.getElementById('toggle').addEventListener('click', function () {
  var value = this.textContent;
  if (value === 'destroy') {
    demo4.destroy();
    this.textContent = 'init';
  } else {
    demo4 = new CSelect(document.getElementById('select-destroy'), options);
    this.textContent = 'destroy';
  }
});
// Demo 5
var select = document.getElementById('select-add');
var demo5 = new CSelect(select, {
  maxWidth: 350,
  animation: 'slideInDown'
});
document.getElementById('addoption').addEventListener('click', function () {
  var date = Date.now();
  select.innerHTML += '<option value="new_option">New option '+ date +'</option>';
  demo5.update();
});
// Demo 6
var demo6 = new CSelect(document.getElementById('custom'), {
  maxWidth: 250,
  customClass: 'select-custom',
  animation: 'fadeIn'
});

              
            
!
999px

Console