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="app app--landing">
  <header class="header">
    <button type="button" class="dropdown">
      <span>Filter by</span>
      <svg width="12" height="12" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg"><path fill="none" stroke-linecap="round" stroke-linejoin="round" d="M11 4L6 9 1 4"></path></svg>
    </button>
    <div class="search">
      <input type="text" id="search" class="search__input" placeholder="Search..." autocomplete="off" />
      <ul class="search__dropdown"></ul>
    </div>
    <button class="user-menu">BL</button>
  </header>

  <div class="side-nav"></div>
  
  <div class="app__content">
    <div class="search-entry">
      <div class="search-entry__header">
        <h1>Animate Search Bar into Header</h1>
        <p>Type the letter "a" into the search bar and select an option from the dropdown.</p>
      </div>
      <div class="search-entry__content">
        <button type="button" class="dropdown">
          <span>Filter by</span>
          <svg width="12" height="12" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
            <path fill="none" stroke-linecap="round" stroke-linejoin="round" d="M11 4L6 9 1 4"></path>
            
          </svg>
        </button>
        <div class="search">
          <input type="text" id="landingSearch" class="search__input" placeholder="Search..." autocomplete="off" />
          <ul class="search__dropdown"></ul>
        </div>
      </div>
    </div>
  </div>
</main>
              
            
!

CSS

              
                .header {
  background-color: #28333f;
  height: 80px;
  top: 0;
  right: 0;
  left: 0;
  padding-right: 24px;
  padding-left: 80px;
  position: fixed;
  display: flex;
  align-items: center;
  opacity: 1;
  transition: opacity 0.3s;
  z-index: 1;
  
  .app--landing & {
    opacity: 0;
    pointer-events: none;
  }
}

.dropdown {
  background-color: transparent;
  width: 192px;
  height: 80px;
  padding: 0 32px;
  border: none;
  position: relative;
  display: flex;
  align-items: center;
  color: #c8d4e0;
  text-align: left;
  
  svg {
    margin-left: auto;
    stroke: #a4b7cc;
  }
  
  &:after {
    content: '';
    position: absolute;
    background-color: #3e4d5e;
    width: 1px;
    height: 64px;
    top: 8px;
    right: 0;
  }
}

.search {
  position: relative;
  flex-grow: 1;
}

.search__input {
  background-color: #28333f;
  width: 100%;
  padding: 29px 40px;
  border: none;
  box-shadow: none;
  color: #748094;
}

.search__dropdown {
  background-color: #1f2a37;
  height: 0;
  right: 0;
  left: 0;
  margin: 4px 0 0;
  padding-left: 0;
  position: absolute;
  overflow: hidden;
  border-bottom-right-radius: 16px;
  border-bottom-left-radius: 16px;
  list-style: none;
  transition: height .4s;
  
  li {
    padding: 20px 40px;
    color: #c8d4e0;
    cursor: pointer;
    
    &:first-child {
      padding-top: 40px;
    }
    
    &:last-child {
      padding-bottom: 40px;
    }
  }
}

.user-menu {
  background-color: #323f4d;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  color: #fff;
}

.search-entry {
  width: 960px;
  top: 50%;
  left: calc(50% + 40px);
  padding: 0 80px;
  position: absolute;
  transform: translate(-50%, -50%);
}

.search-entry__header {
  background-color: #323F4D;
  padding: 40px 40px 64px;
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  transform: scaleY(1);
  transform-origin: top;
  transition: all 0.3s;
  
  h1 {
    margin: 0;
    color: #f5f7f9;
    font-size: 24px;
    line-height: 36px;
  }
  
  p {
    margin-top: 4px;
    margin-bottom: 0;
    color: #a4b7cc;
    font-size: 16px;
    line-height: 24px;
  }
}

.search-entry__content {
  background-color: #28333f;
  padding: 0 24px 0 8px;
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 16px;
  display: flex;
}


// Additional styles needed for the base demo
*, *:before, *:after {
  box-sizing: border-box;
}

body {
  background-color: #3E4D5E;
  color: #fff;
  font-family: Lato, Helvetica, Arial, sans-serif;
}
  
::-webkit-input-placeholder {
  color: #748094;
}

::-moz-placeholder {
  color: #748094;
}

.side-nav {
  background-color: #28333f;
  width: 80px;
  top: 0;
  bottom: 0;
  left: 0;
  position: fixed;
}
              
            
!

JS

              
                const search = document.getElementById('landingSearch');
const searchDropdown = document.querySelector('.search-entry .search__dropdown');
const app = document.querySelector('.app');
const appHeader = document.querySelector('.header');
const searchEntry = document.querySelector('.search-entry');

const closeSearchDropdown = () => {
  searchDropdown.style.height = 0;
  searchDropdown.innerHTML = '';
}

// Search entry animation
let tl = anime.timeline({
  easing: 'linear'
});

const searchHandler = (e) => {
  if (e.type === 'click') {
    e.preventDefault();
    search.value = e.target.textContent;
    closeSearchDropdown();
  }
  
  if (e.keyCode === 13 || e.type === 'click') {
    e.preventDefault();
    search.blur();
    closeSearchDropdown();
    
    tl
    .add({
      targets: [
        document.querySelector('.search-entry__header').children,
        document.querySelector('.search-entry__content').children
      ],
      opacity: 0,
      duration: 500
    })
    .add({
      targets: '.search-entry__header',
      paddingTop: 0,
      paddingBottom: 0,
      opacity: 0,
      height: 0,
      duration: 500,
      offset: '-=500'
    })
    .add({
      targets: '.search-entry',
      top: 0,
      translateX: ['-50%', '-50%'],
      translateY: ['-50%', 0],
      duration: 1000,
      offset: '-=500'
    });
    
    setTimeout(() => {
      searchEntry.style.transition = 'all 0.3s';
      anime({
        targets: '.search-entry',
        padding: 0,
        easing: 'linear',
        duration: 500
      });
      anime({
        targets: '.search-entry',
        width: '100%',
        translateX: ['-50%', 0],
        translateY: [0, 0],
        left: 0,
        easing: 'linear',
        duration: 500,
        offset: '-=500'
      });
      
      document.getElementById('search').value = search.value;
      
      anime({
        targets: '.header',
        opacity: 1,
        delay: 500,
        complete: function(anim) {
          appHeader.style.pointerEvents = 'auto';
        }
      });
    }, 1100);
  }
};

search.addEventListener('keyup', searchHandler);

// Typeahead search functionality
const matches = [
  'Austin, TX',
  'Downtown, Austin, TX',
  'Austin, MN',
  'Lake Austin, TX',
  'Augusta, GA',
  'Auburn, AL',
  'Aurora, CO'
];

const typeaheadHandler = (e) => {
  const userInput = e.target.value.toLowerCase();
  
  if (userInput.length === 0) {
    closeSearchDropdown();
  }

  const filteredMatches = matches.filter((match) => match.toLowerCase().includes(userInput)).sort().splice(0, 5);
  searchDropdown.innerHTML = '';
  
  filteredMatches.forEach(item => {
    const searchResult = document.createElement('li');
    searchResult.textContent = item;
    searchDropdown.appendChild(searchResult);
    searchResult.addEventListener('click', searchHandler);
  });
  
  if (searchDropdown.children[0] === undefined) {
    return searchDropdown.style.height = 0;
  }

  let totalChildrenHeight = (searchDropdown.children[0].offsetHeight - 20) * filteredMatches.length + 40;
  searchDropdown.style.height = totalChildrenHeight + 'px';
};

search.addEventListener('input', typeaheadHandler);
              
            
!
999px

Console