Chapter 25: Form Attributes, Organization & Accessibility

The enterkeyhint Attribute

Customizing mobile virtual keyboard action keys (`enter`, `done`, `go`, `next`, `previous`, `search`, `send`), multi-step wizard ergonomics, and IME integration.

LEARNING OBJECTIVES
  • Understand how the global enterkeyhint attribute customizes the action key label and icon on mobile virtual keyboards.
  • Master the complete enumeration of enterkeyhint values: enter, done, go, next, previous, search, and send.
  • Align enterkeyhint semantics with user intent: using next for sequential form fields and send / go for final submission controls.
  • Implement seamless mobile field progression by pairing enterkeyhint="next" with standard JavaScript focus-advance listeners.
🎬 INTERACTIVE VISUAL PIPELINE Core Architecture Simulation
🌐
1. Input
Directives & Tags
⚙️
2. Parse
Tokenizer & AST
🌳
3. Layout
Box Model & Flow
🎨
4. Render
GPU Paint & Composite
PHASE 1: INPUT & DIRECTIVES
Browser receives declarative markup stream, parsing tag tokens and initializing component state.

📖 The Mental Model & Story (Intuitive Foundation)

Imagine walking through a high-security office building with a series of automated doors.

  • At Door 1, the digital button on the wall is glowing blue and clearly labeled "CONTINUE TO NEXT ROOM". You tap it, and the next door opens.
  • At the final security checkpoint, the button changes color and reads "DISPATCH GUARDS & LOCK VAULT".

Because the button's label dynamically reflects the exact consequence of pressing it, you never hesitate or fear that tapping the button will trigger the wrong action.

On mobile smartphones and tablets, the bottom-right key on the virtual keyboard is that action trigger.

GENERIC / CONFUSING ACTION KEY:
┌────────────────────────────────────────────────────────┐
│  [?123]      [      space      ]      [ return ]       │
└────────────────────────────────────────────────────────┘
Does pressing [return] insert a newline? Submit my order? Close the keyboard?

SEMANTICALLY OPTIMIZED ACTION KEYS (Via enterkeyhint):
┌───────────────────────────┐  ┌───────────────────────────┐  ┌───────────────────────────┐
│ [?123]   [ space ] [ Next]│  │ [?123]   [ space ] [Search│  │ [?123]   [ space ] [ Send]│
└───────────────────────────┘  └───────────────────────────┘  └───────────────────────────┘

By default, mobile keyboards render a vague, ambiguous "Return" or generic arrow icon. The HTML5 enterkeyhint attribute tells the mobile operating system (iOS, Android) exactly what label or icon to render on that action key, communicating clear transactional intent to the user.


Technical Deep Dive & Specifications

The Seven enterkeyhint Values

The WHATWG HTML Living Standard specifies seven standardized keywords for enterkeyhint:

+----------------------------------------------------------------------------------------------------+
|                                    ENTERKEYHINT ENUMERATION MATRIX                                 |
+----------------------------------------------------------------------------------------------------+
| Attribute Value | Mobile Action Key Visual (iOS / Android) | Semantic Purpose / Real-World Context |
+-----------------+------------------------------------------+---------------------------------------+
| `next`          | "Next" text / Forward Right Arrow (`➜`)  | Advances focus to next field in form  |
| `previous`      | "Previous" text / Backward Arrow (`⬅`)   | Moves focus to previous field         |
| `go`            | "Go" text / Bold Blue Action Arrow       | Navigates to a URL or initiates task  |
| `send`          | "Send" text / Paper Airplane Icon        | Dispatches a chat message or comment  |
| `search`        | "Search" text / Magnifying Glass Icon (`🔍`)| Submits search queries / filtering |
| `done`          | "Done" text / Checkmark Icon (`✔`)       | Concludes input; closes soft keyboard |
| `enter`         | "Return" text / Newline Arrow (`↵`)      | Inserts carriage return newline       |
+----------------------------------------------------------------------------------------------------+

Platform Rendering Differences

┌────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                               OPERATING SYSTEM IME PRESENTATION                                    │
├────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Apple iOS (Safari/WebKit)   │ Renders localized blue action button text: "Next", "Search",         │
│                             │ "Send", "Go", "Done", or "return".                                   │
├─────────────────────────────┼──────────────────────────────────────────────────────────────────────┤
│ Google Android (Gboard)     │ Renders dynamic icons on the bottom-right key: magnifying glass for   │
│                             │ search, paper plane for send, right arrow for next, check for done.  │
├─────────────────────────────┼──────────────────────────────────────────────────────────────────────┤
│ Desktop Browsers (Chrome/Mac)│ Has NO visual impact on physical hardware keyboards.                 │
└────────────────────────────────────────────────────────────────────────────────────────────────────┘

[!NOTE] enterkeyhint is an interactive UI hint for Input Method Editors (IMEs) and software keyboards. It has zero visual impact on physical desktop keyboards, but is transformative for mobile conversion rates.


Orchestrating Sequential Forms with enterkeyhint="next"

On mobile devices, tapping enterkeyhint="next" does not automatically jump focus to the next field unless implemented natively by the browser or wired via a clean JavaScript helper.

// Universal Next-Field Keyboard Advancement Listener
document.addEventListener('keydown', (event) => {
  if (event.key === 'Enter' && event.target.getAttribute('enterkeyhint') === 'next') {
    event.preventDefault(); // Prevent form submission
    
    // Find all focusable form controls in DOM order
    const form = event.target.form;
    if (!form) return;
    
    const focusables = Array.from(form.elements).filter(
      el => !el.disabled && el.type !== 'hidden' && el.tabIndex !== -1
    );
    
    const currentIndex = focusables.indexOf(event.target);
    const nextElement = focusables[currentIndex + 1];
    
    if (nextElement) {
      nextElement.focus();
    }
  }
});

The Complete Mobile Input Stack

To build the highest possible fidelity mobile form field, combine all three modern mobile attributes:

<!-- The Holy Trinity of Mobile Form Field Ergonomics -->
<input 
  type="text" 
  id="shipping-zip"
  name="zip"
  inputmode="numeric" 
  enterkeyhint="next" 
  autocomplete="postal-code"
  placeholder="90210"
  required
>
  1. autocomplete="postal-code": Triggers operating system autofill suggestions.
  2. inputmode="numeric": Summons the large 10-digit number keypad.
  3. enterkeyhint="next": Changes the action button to "Next" to continue down the checkout flow.

SYS: ACTIVE
HULL: 98%
CORE: STABLE
NET: ONLINE
HTML STARSHIP CODE TERMINAL example.html
LIVE RENDER & DIAGNOSTICS CORE TEMP: 45°C
INSPECTING DOM: VALID
TAGS: SCANNING...

💻 Interactive Code Playground

Starter Code

Line-by-Line Code Breakdown

  • Lines 73 & 78 (enterkeyhint="next"): Configures the mobile virtual keyboard to display "Next" or a forward arrow on the First Name and Last Name inputs.
  • Line 83 (enterkeyhint="done"): On the final Street Address input, displays "Done" or a checkmark, communicating that the sequential data entry is complete.
  • Line 97 (enterkeyhint="send"): Shows a paper airplane icon or "Send" button on mobile keyboards in the chat input.
  • Line 107 (enterkeyhint="search"): Displays a magnifying glass search icon on the search bar's action key.
  • Lines 112–122 (JavaScript Focus Advancement): Intercepts the Enter keypress when enterkeyhint="next" is present and programmatically shifts focus to the next <input> in sequence.

Expected Browser Render Output


SYS: ACTIVE
HULL: 98%
CORE: STABLE
NET: ONLINE
HTML STARSHIP CODE TERMINAL playground.html
LIVE RENDER & DIAGNOSTICS CORE TEMP: 45°C
INSPECTING DOM: VALID
TAGS: SCANNING...
┌────────────────────────────────────────────────────────┐
│ 1. Sequential Delivery Form                            │
│                                                        │
│ First Name  [enterkeyhint="next"]                      │
│ ┌────────────────────────────────────────────────────┐ │
│ │                                                    │ │ (Soft key shows: "Next")
│ └────────────────────────────────────────────────────┘ │
│ Last Name  [enterkeyhint="next"]                       │
│ ┌────────────────────────────────────────────────────┐ │
│ │                                                    │ │ (Soft key shows: "Next")
│ └────────────────────────────────────────────────────┘ │
│ Street Address  [enterkeyhint="done"]                  │
│ ┌────────────────────────────────────────────────────┐ │
│ │                                                    │ │ (Soft key shows: "Done")
│ └────────────────────────────────────────────────────┘ │
│                                                        │
│ [ Save Address ]                                       │
├────────────────────────────────────────────────────────┤
│ 2. Instant Messenger Box                               │
│ ┌───────────────────────────────────────┬────────────┐ │
│ │ Type a message... [enterkeyhint="send"]│ [ Send ]  │ │ (Soft key shows: "Send")
│ └───────────────────────────────────────┴────────────┘ │
└────────────────────────────────────────────────────────┘

🏋️ Hands-On Exercise

🎯 The Challenge: Optimize the Mobile Checkout Flow

You are optimizing a mobile checkout page. Mobile user testing revealed that users get confused because the mobile keyboard always shows a generic "Return" button on all fields, causing users to accidentally submit the form before completing their address!

Instructions:

  1. Configure enterkeyhint="next" on the First Name, Last Name, and City inputs.
  2. Configure enterkeyhint="search" on the Postal Code lookup input.
  3. Configure enterkeyhint="go" or enterkeyhint="done" on the final Credit Card input.

🏁 Starter Code Sandbox

SYS: ACTIVE
HULL: 98%
CORE: STABLE
NET: ONLINE
STARTER CODE SANDBOX exercise.html
LIVE RENDER & DIAGNOSTICS CORE TEMP: 45°C
INSPECTING DOM: VALID
TAGS: SCANNING...

⚠️ Common Pitfalls

  1. Expecting enterkeyhint to Auto-Advance Focus Without JS: Setting enterkeyhint="next" changes the visual label on the keyboard. In standard web forms, pressing Enter still submits the form by default unless you handle the keydown event in JavaScript.
  2. Using enterkeyhint="send" on Standard Multiline Textareas: On large textareas where users write paragraphs, using send may confuse users who expect Return to insert a newline. Use enterkeyhint="enter" on standard textareas.
  3. Invalid Keyword Values: Values like enterkeyhint="submit" or enterkeyhint="continue" are invalid keywords and will default to standard enter.

💡 Pro Tips

  1. Chat App Ergonomics: For instant messaging apps, use enterkeyhint="send" on single-line inputs (<input type="text">), and allow Shift+Enter to insert newlines if using a <textarea>.
  2. Combine with inputmode and autocomplete: Never use enterkeyhint in isolation. Always specify the full trio: inputmode (keypad shape), enterkeyhint (action button label), and autocomplete (credential autofill).

📌 Key Takeaways

  • The enterkeyhint attribute customizes the action button label/icon on mobile touchscreen virtual keyboards.
  • The 7 standardized keywords are: enter, done, go, next, previous, search, and send.
  • Use enterkeyhint="next" on sequential form fields to visually prompt users to continue.
  • Use enterkeyhint="send" on chat and comment inputs, and enterkeyhint="search" on search bars.
  • Pairing enterkeyhint="next" with a small JavaScript listener creates seamless native-app-like focus advancement.
  • --
⭐ LEARN: HTML 🌟 ⚔️ QUIZ BATTLE ARENA // ACTIVE
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 1 / 3

Which enterkeyhint value should be used on an instant chat messenger text input to display a "Send" or paper airplane icon on mobile virtual keyboards?

Question 1 / 3 Topic: HTML Fundamentals
00:45 REMAINING
XP REWARD
+250 XP
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 2 / 3

What happens if a developer specifies an unrecognized value like enterkeyhint="proceed"?

Question 2 / 3 Topic: HTML Fundamentals
00:45 REMAINING
XP REWARD
+250 XP
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 3 / 3

Does declaring enterkeyhint="next" on an <input> automatically shift focus to the next input when pressed on standard HTML forms without JavaScript?

Question 3 / 3 Topic: HTML Fundamentals
00:45 REMAINING
XP REWARD
+250 XP