Add an autocomplete dropdown below your input to suggest possible values in your form. You can populate the list of autocomplete options dynamically as well.


  <div class="row">
    <div class="col s12">
      <div class="row">
        <div class="input-field col s12">
          <i class="material-icons prefix">textsms</i>
          <input type="text" id="autocomplete-input" class="autocomplete">
          <label for="autocomplete-input">Autocomplete</label>


The data is a json object where the key is the matching string and the value is an optional image url.

  document.addEventListener('DOMContentLoaded', function() {
    var elems = document.querySelectorAll('.autocomplete');
    var instances = M.Autocomplete.init(elems, options);

  // Or with jQuery

      data: {
        "Apple": null,
        "Microsoft": null,
        "Google": ''


Name Type Default Description
data Object {} Data object defining autocomplete options with optional icon strings.
limit Number Infinity Limit of results the autocomplete shows.
onAutocomplete Function null Callback for when autocompleted.
minLength Number 1 Minimum number of characters before autocomplete starts.
sortFunction Function Sort function that defines the order of the list of autocomplete options.

This is the default compareFunction. You can write your own compareFunction by passing in a function with these same 3 parameters. You can read more about how a compareFunction works here.

  // Sort function for sorting autocomplete results
  function (a, b, inputString) {
    return a.indexOf(inputString) - b.indexOf(inputString);

To disable sorting and use the values as they appear in the data object, use a falsy value.


Because jQuery is no longer a dependency, all the methods are called on the plugin instance. You can get the plugin instance like this:

  var instance = M.Autocomplete.getInstance(elem);

  /* jQuery Method Calls
    You can still use the old jQuery plugin method calls.
    But you won't be able to access instance properties.

    $('.autocomplete').autocomplete('methodName', paramName);

Open autocomplete dropdown.;


Close autocomplete dropdown.



Select a specific autocomplete options.


Element: Element of the autocomplete option.



Update autocomplete options data.


Object: Autocomplete options data object.

  "Apple": null,
  "Microsoft": null,
  "Google": ''


Destroy plugin instance and teardown



Name Type Description
el Element The DOM element the plugin was initialized with.
options Object The options the instance was initialized with.
isOpen Boolean If the autocomplete is open.
count Number Number of matching autocomplete options.
activeIndex Integer Index of the current selected option.
dropdown Dropdown Instance of the dropdown plugin for this autocomplete.