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

              
                <form onsubmit="return false;" class="pure-form" style="border-top: 1px solid #eee;border-bottom:1px solid #eee;background:#fafafa;margin:30px 0;padding:20px 10px;text-align:center">
  <input id="user-input" autofocus type="text" placeholder="Type a word ..." style="width:100%;max-width:600px;outline:0" />
</form>
<ul id="definitions"></ul>
              
            
!

CSS

              
                .autocomplete-suggestions {
  text-align: left;
  cursor: default;
  border: 1px solid #ccc;
  border-top: 0;
  background: #fff;
  box-shadow: -1px 1px 3px rgba(0, 0, 0, 0.1);
  position: absolute;
  display: none;
  z-index: 9999;
  max-height: 254px;
  overflow: hidden;
  overflow-y: auto;
  box-sizing: border-box;
}
.autocomplete-suggestion {
  position: relative;
  padding: 0 0.6em;
  line-height: 23px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 1.02em;
  color: #333;
}
.autocomplete-suggestion b {
  font-weight: normal;
  color: #1f8dd6;
}
.autocomplete-suggestion.selected {
  background: #f0f0f0;
}

#definitions {
  max-width: 600px;
  margin: 0 auto;
}

              
            
!

JS

              
                // Get your own API key at https://www.wordsapi.com
const apiKey = "dBviz3mISgmshbFzBbOTIhH7w7Orp1LP63njsnBgeDm19QW5ky";

const definitionList = document.getElementById("definitions");

/*
 * Look up word suggetions based on user input from Words API.
 * https://www.wordsapi.com
 *
 * */
function getSuggestions(input) {
  const url = `https://wordsapiv1.p.mashape.com/words/?letterPattern=^${input}.*&hasDetails=definitions`;
  return fetch(url, {
    method: "GET",
    headers: {
      "Content-Type": "application/json",
      "X-RapidAPI-Key": apiKey
    }
  }).then(resp => resp.json());
}

/*
 * Get the definition of a word.
 */
function getDefinitions(term) {
  const url = `https://wordsapiv1.p.mashape.com/words/${term}`;
  return fetch(url, {
    method: "GET",
    headers: {
      "Content-Type": "application/json",
      "X-RapidAPI-Key": apiKey
    }
  })
    .then(resp => resp.json())
    .then(resp => {
      return resp.results;
    });
}

/*
 * Show definitions in a list.
 *
 */
function showDefinitions(definitions) {
  definitionList.innerHTML = "";
  definitions.forEach(definition => {
    const li = document.createElement("li");
    li.textContent = `${definition.partOfSpeech} - ${definition.definition}`;
    definitionList.appendChild(li);
  });
}

new autoComplete({
  selector: "#user-input",
  minChars: 1,
  source: function(term, suggest) {
    getSuggestions(term).then(response => {
      suggest(response.results.data);
    });
  },
  onSelect: function(e, term, item) {
    getDefinitions(term).then(showDefinitions);
  }
});

              
            
!
999px

Console