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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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="wrapper">
  <form class="searchbox">
    <input type="search" placeholder="Search" id="search" autocomplete="off">
    <div id="search-autocomplete" class="search-autocomplete">
      <ul>
      
        <li class="load-more"><a href="#">Load more</a></li>
        <li class="no-results">No results.</li>
        <li class="error">%err%</li>
      </ul>
      <div class="loader">
        <div class="spinner">
          <div class="bounce1"></div>
          <div class="bounce2"></div>
          <div class="bounce3"></div>
        </div>
      </div>
    </div>
  </form>
</div>

<p class="description">
  Start by typing in the search box to search Google
</p>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Open+Sans:400,300,600);

$padding: 7px 10px;


body {
  background: #efefef;
  padding: 20px;
  font-family: 'Open Sans', sans-serif;
}
.description {
  text-align: center;
  font-size: 0.8em;
  color: #bbb;
  text-shadow: 0 2px 1px #fff;
}

b, strong {
  font-weight: 600;
}

.wrapper {
  margin: 0 auto;
  display: block;
  background: #fff;
  width: 400px;
  padding: 10px;
  box-shadow: 0 0 5px rgba(10, 10, 10, 0.4);
}

.searchbox {
  width: 100%;
  position: relative;
  
  input[type=search] {
    width: 100%;
    border: 1px solid #eee;
    padding: $padding;
    -webkit-appearance: none;
  }
  
  .search-autocomplete {
    display: none;

    position: absolute;
    top: 0;
    left: 0;
    right: 0;

    font-size: 0.9em;
    border: 1px solid #eee;
    border-top: none;
    background: #fff;
    box-shadow: 0 4px 4px rgba(10, 10, 10, 0.1);

    max-height: 300px;
    overflow-y: auto;
    
    
    ul {
      list-style: none;
      margin: 0;
      padding: 0;
    }
    li, a {
      display: block;
    }
    li {
      border-bottom: 1px solid #eee;
      color: #0074D9;
    }
    li:last-of-type {
      border-bottom: none;
    }
    li:hover, li:active {
      background: #fafafa;
      color: #FF4136;
    }
    
    a {
      padding: $padding;
      color: inherit;
      text-decoration: none;
    }
    
    .search-description {
      font-size: 0.8em;
      color: #999;
      font-weight: 300;
      display: block;
    }
    
    .loader, .load-more, .no-results, .error {
      padding: $padding;
      text-align: center;
    }
    .load-more {
      font-size: 0.8em;
      color: #0074D9;
    }
    .error, .error:hover, .error:active {
      color: #FF4136;
    }
    .no-results, .no-results:hover, .no-results:active {
      color: #999;
    }
  }
}












/* SpinKit by Tobias Ahlit
/* https://github.com/tobiasahlin/SpinKit
/**********************************************************/
.spinner {
  margin: auto;
  width: 70px;
  text-align: center;
}

.spinner > div {
  width: 14px;
  height: 14px;
  background-color: #0074D9;

  border-radius: 100%;
  display: inline-block;
  -webkit-animation: bouncedelay 1.4s infinite ease-in-out;
  animation: bouncedelay 1.4s infinite ease-in-out;
  /* Prevent first frame from flickering when animation starts */
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
}

.spinner .bounce1 {
  -webkit-animation-delay: -0.32s;
  animation-delay: -0.32s;
}

.spinner .bounce2 {
  -webkit-animation-delay: -0.16s;
  animation-delay: -0.16s;
}

@-webkit-keyframes bouncedelay {
  0%, 80%, 100% { -webkit-transform: scale(0.0) }
  40% { -webkit-transform: scale(1.0) }
}

@keyframes bouncedelay {
  0%, 80%, 100% { 
    transform: scale(0.0);
    -webkit-transform: scale(0.0);
  } 40% { 
    transform: scale(1.0);
    -webkit-transform: scale(1.0);
  }
}
              
            
!

JS

              
                (function() {
  var searchbox = $('#search'),
      autocomplete = $('#search-autocomplete'),
      loadMoreButton = $('.load-more', autocomplete),
      spinner = $('.loader', autocomplete),
      noResults = $('.no-results', autocomplete),
      error = $('.error', autocomplete);
  
  var currentOffset = 0,
      // some random URL to load because we don't use the result anyway, just so the request will succeed :P
      searchUrl = 'https://raw.githubusercontent.com/ghosh/uiGradients/master/gradients.json', //'https://www.crossorigin.me/https://ajax.googleapis.com/ajax/services/search/web',
      lastSearch = '',
      searchTimeout = 0.5, //seconds
      searchTimer;

  function loadData() {
    noResults.hide();
    error.hide();
    loadMoreButton.hide();
    spinner.show();
    
    if(searchbox.val() !== lastSearch) {
      $('.search-result', autocomplete).remove();
      currentOffset = 0;
    }

    lastSearch = searchbox.val();
    
    $.ajax({
      type: 'GET',
      url: searchUrl,
      dataType: 'text',
      data: {
        'v': '1.0',
        'q': lastSearch,
        'start': currentOffset
      },
      success: function(data) {
        // Since the web search API is dead we have to fake it for the demo
        // Can't be bothered to actually remove the AJAX request so it stays ;)
        data = '{"responseData": {"results" : [{"url": "https://www.google.com","titleNoFormatting": "Quibusdam minus","content": "Quibusdam minus saepe incididunt tincidunt congue repellendus malesuada pretium veniam explicabo molestiae cupiditate natoque praesentium nascetur, vitae anim risus soluta quisque aliquip harum modi? Maecenas esse culpa mattis! Natus voluptatum."},{"url": "https://www.google.com","titleNoFormatting": "Possimus! Quia, atque illo","content": "Possimus! Quia, atque illo imperdiet quam, lacus penatibus bibendum cupiditate? Nihil pellentesque velit voluptatem sodales lacus tellus torquent. Deserunt eum incidunt et."},{"url": "https://www.google.com","titleNoFormatting": "Cubilia amet eos proident","content": "Cubilia amet eos proident blandit irure nobis diam! Dignissim sed officiis aut, arcu, nulla necessitatibus fermentum officia fermentum."},{"url": "https://www.google.com","titleNoFormatting": "Wisi, rhoncus consectetuer","content": "Dictum iure blandit cupidatat, laborum potenti cupidatat magnam nostrum nibh! Wisi, rhoncus consectetuer netus! Enim vitae mollis ullamcorper fames eiusmod?"},{"url": "https://www.google.com","titleNoFormatting": "Cras tempore inventore","content": "Debitis cum auctor, nibh, etiam! Cras tempore inventore, nascetur possimus."}]}}';
        
        var json = $.parseJSON(data);
        
        if(json &&
           json.responseData &&
           json.responseData.results &&
           json.responseData.results.length > 0) {
          for(var i = 0; i < json.responseData.results.length; ++i) {
            $('<li class="search-result">' +
                '<a href="'+ json.responseData.results[i].url +'" target="_blank">' +
                  json.responseData.results[i].titleNoFormatting +
                  '<span class="search-description">' +
                    json.responseData.results[i].content +
                  '</span>' +
                '</a>' +
              '</li>').insertBefore(loadMoreButton);
          }
          
          noResults.hide();
          loadMoreButton.show();
          error.hide();
        } else {
          noResults.show();
          loadMoreButton.hide();
          error.hide();
        }
        
        if(json &&
           !json.responseData &&
            json.responseDetails) {
          noResults.hide();
          loadMoreButton.hide();
          error.text(json.responseDetails).show();
          console.error(json.responseDetails);
        }
        
        spinner.hide();
        currentOffset += json.responseData.results.length;
      },
      error: function(jqXHR, textStatus, errorThrown) {
        console.error(errorThrown);
        
        error.text(textStatus + ': ' + errorThrown).show();
        
        loadMoreButton.hide();
        noResults.hide();
        spinner.hide();
      }
    });
  }
  
  searchbox.on('focus', function() {
    if($(this).val().length > 0) {
      autocomplete.slideDown('fast');
    }
  })
  .on('input propertychange paste', function() {
    //this will handle pasting text and clearing text with browser built in clear button
    $(this).trigger('keyup');
  })
  .on('keydown', function() {
    clearTimeout(searchTimer);
  })
  .on('keyup', function() {
    if($(this).val().length > 0) {
      clearTimeout(searchTimer);
      searchTimer = setTimeout(loadData, searchTimeout * 1000);
      autocomplete.slideDown('fast');
    } else {
      clearTimeout(searchTimer);
      autocomplete.slideUp('fast');
    }
  });

  $(document).on('click', function(e) {
    //click anywhere outside searchbox to close
    if(!$(e.target).closest('.searchbox').length) {
      if(autocomplete.is(':visible')) {
        autocomplete.slideUp('fast');
        clearTimeout(searchTimer);
      }
    }
  });

  
  autocomplete.css('top', (searchbox.outerHeight()) + 'px');
  loadMoreButton.on('click', loadData)
                .hide();
  noResults.hide();
  error.hide();
  
}());
              
            
!
999px

Console