To limit the height of the autocomplete feature to a maximum of 100px in your example, you simply need to include max-height: 100px
and overflow-y: scroll
within the style for the .autocomplete-items
class.
Here is a demonstration:
// JavaScript code for autocomplete functionality
function autocomplete(inp, arr) {
// Function logic goes here...
}
// Array of country names for autocomplete suggestions
var countries = ["Afghanistan", "Albania", ... ];
// Initialize autocomplete function on input element with id "myInput"
autocomplete(document.getElementById("myInput"), countries);
/* CSS styles for autocomplete feature */
.autocomplete {
/* Styles for container go here... */
}
input[type=submit] {
/* Button styles */
}
.autocomplete-items {
/* Styles for autocomplete dropdown */
max-height: 100px;
overflow-y: scroll;
}
.autocomplete-active {
/* Active item styles */
}
<h2>Autocomplete</h2>
<p>Start typing:</p>
<form autocomplete="off" action="/action_page.php">
<div class="autocomplete" style="width:300px;">
<input id="myInput" type="text" name="myCountry" placeholder="Country">
</div>
<input type="submit">
</form>