Web Dev — Show Search Button on iOS Keyboard

How to display a Search action on the software keyboard across iOS and Android and handle the resulting events.

Feb 20, 2025 · 1 min read · 138 Words · -Views -Comments · Programming
Frontend Development Hardware 🇨🇳 阅读中文版
Read with AI

Choose an AI assistant

ChatGPT Open in a new tab with the article link and prompt
Claude Copy the prompt, then open Claude

Open Claude
Trouble reading the article?

If the prompt is missing, copy the full prompt below into your AI assistant. If the AI cannot read the article, paste the visible passage you want to discuss and add your question.

On mobile, focusing a web input field brings up the system keyboard. If you want a “Search” button to appear on the keyboard, some attributes are needed.

input type=“search”

With the following, iOS does not show a Search button in testing, while Android does.

<input type="search" />

enterKeyHint=“search”

With the following, iOS does show the Search button. Android also displays it correctly.

<input type="search" enterKeyHint="search" />

search event firing

On Android, pressing the Search button fires the search event. On iPhone, pressing Search only triggers the Enter event. So listen for Enter and check accordingly.

el.addEventListener('search', (e) => {
  console.log(e)
})

el.addEventListener('enter', (e) => {
  if (e.key === 'Enter') {
    console.log('Search')
  }
})

Final Thoughts

The above solves showing a Search button on the mobile keyboard for both iOS and Android when an input is focused.

References

Authors
Developer, digital product enthusiast, tinkerer, sharer, open source lover