How to use autocomplete (suggestion) in bootstrap?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

Today, I am going to show you. How to use autocomplete (suggestion) in bootstrap with code example.

Here, we will use the .typeahead class to make use of autocomplete in bootstrap.

In this article, we will learn to implement dynamic autocomplete search using Bootstrap Typeahead. Bootstrap Typeahead is a plugin that helps to add a beautiful autocomplete option in the search bar.

In this approach, we will be taking static data for autocomplete, but we can also use dynamic JSON data as well, to show search options.


Let’s look at the following example to understand how it basically works:

<!DOCTYPE html>
<html lang="en">

    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="">

    <script src="">

    <link href="" rel="stylesheet" />

        body {
            background: #3F51B5;
        .page-title {
            color: #ffffff;
            font-weight: 800;
        .typeahead {
            width: 50%;
        .autocomplete {
            position: relative;
            display: inline-block;
        .autocomplete-items {
            position: absolute;
            z-index: 99;
            top: 100%;
            left: 0;
            right: 0;

<body style="text-align: center">
        <p class="page-title">Suggest the states of India</p>

        <input type="text" class="typeahead" data-provide="typeahead" placeholder="Enter name of states of India " />

        // Initializes  input( name of states)
        // with a typeahead
        var $input = $(".typeahead");
            source: [
                "Andhra Pradesh",
                "Arunachal Pradesh",
                "Himachal Pradesh",
                "Madhya Pradesh",
                "Tamil Nadu",
                "Uttar Pradesh",
                "West Bengal",
            autoSelect: true,

        $input.change(function() {
            var current = $input.typeahead("getActive");
            matches = [];

            if (current) {

                // Some item from your input matches
                // with entered data
                if ( == $input.val()) {


In the above code, we have used .typeahead class to autocomplete in bootstrap

Check the output of the above code example.

Bootstrap, Use, Autocomplete

All the best 👍

Premium Content

You can get all the below premium content directly in your mail when you subscribe us


Portfolio Template

View | Get Source Code

Cheat Sheets

Cheat Sheets Books are basically Important useful notes which we use in our day-to-day life.

I'm working on some more Cheat Sheets book on Jquery, TypeScript, React js and for other languages. I will send it once it's completed.

Related Posts