brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: enterkeyhint changes the label of the Enter key on a phone keyboard

Web-Development
~/tips/tip-html-enterkeyhint

cat ~/tips/tip-html-enterkeyhint.md

Sets the label of the Enter key on mobile keyboards, like search, next or send.

On a phone, the key at the bottom right of the keyboard says “return” on every field unless you tell it otherwise. Searching, sending a message and going to the next field are not the same action, and enterkeyhint lets you say which one it is. I’d add it to every form I build, since it costs one attribute.

It is a global attribute for form controls and contenteditable elements:

<input type="search" enterkeyhint="search">
<input type="text" name="name" enterkeyhint="next">
<textarea enterkeyhint="send"></textarea>
<input type="url" enterkeyhint="go">

The allowed values are enter, done, go, next, previous, search and send. So a login form can use next on the username and go on the password, and a search box shows a search key instead of return.

It pairs well with inputmode, which picks the keyboard layout, while enterkeyhint only changes that one key. If you leave it out, the browser may guess from inputmode, type or pattern.

Caveats: it is a hint and nothing more. The label or icon depends on the browser, the keyboard app and the language, so the key may still say something slightly different. It also does not change what the key does. Pressing Enter in a form field still submits the form (or not) based on your markup, so enterkeyhint="send" on a field that does nothing on Enter is a lie to the user.

It has worked in browsers since November 2021. On a desktop keyboard it has no visible effect, so test it on a real phone or an emulator.

Further reading: MDN: enterkeyhint

More Web-Development tips ab -n 200 -c 10 https://example.com/ console.assert(items.length > 0, 'cart is empty', items) document.designMode = "on" function save(item) { Save draft All Web-Development tips (67) All topics

Link