HTML inputmode gives the browser a hint about the keyboard a field needs. For a digit-only reference code, start with type="text" inputmode="numeric"; for a quantity that users can increment, consider type="number". The hint does not validate the value or guarantee an identical keyboard on every phone. MDN's inputmode reference documents that distinction.
A student project lookup form can work on a laptop while forcing phone users to switch keyboard layouts for every entry. Fix the field contract first, then test the actual mobile task. This guide covers keyboard selection, identifier preservation, decimal entry, debugging, and a focused CI check. Use the broader website form testing checklist for submission, server errors, and recovery.
HTML inputmode launch checklist
- Decide whether each value is text, an identifier, or a mathematical number.
- Choose the input type for its meaning and behavior.
- Add a keyboard hint where it helps users enter the accepted characters.
- Keep labels, format instructions, autocomplete, and validation consistent.
- Preserve leading zeros and test pasted values.
- Try the field on supported phones with the on-screen keyboard open.
- Save markup and value-preservation assertions in CI.
Choose inputmode numeric, decimal, or another keyboard hint
The available values are none, text, tel, url, email, numeric, decimal, and search. Useful choices include:
numericfor a digit-focused keyboard.decimalfor fractional entry, with a locale-dependent decimal separator.telfor telephone-style entry.emailorurlfor characters useful in those addresses.searchfor a search-oriented keyboard.
Minus-key availability varies, including for numeric and decimal layouts. Do not require negative entry without checking that users can enter it. none requests no virtual keyboard; avoid it on an ordinary form where visitors need to type. These are hints described by MDN, rather than a portable keyboard design API.
Write the accepted examples before choosing a hint. If a membership reference accepts 001234, a numeric keyboard is helpful. If it also accepts AB-1234, users need a practical way to enter letters and punctuation. A digit-focused layout that makes half the valid values difficult to enter is the wrong default.
Separate inputmode from type, autocomplete, and validation
Each attribute answers a different question. type selects the control's behavior, autocomplete identifies the information expected for autofill, and inputmode suggests an entry modality. The HTML Standard's form guidance explains why those choices are independent.
For an email field, type="email" already supplies email-specific behavior. Do not change it to text just to add a keyboard hint. Keep a visible label, a stable submission name, and the appropriate autocomplete token. Our HTML autocomplete attribute guide covers saved-data hints and repeated address groups.
For a reference code, define validation separately. This example accepts exactly six ASCII digits and leaves the value as text:
<label for="reference">Project reference</label>
<p id="reference-help">Enter the six digits, including any leading zeros.</p>
<input id="reference" name="reference" type="text"
inputmode="numeric" pattern="[0-9]{6}" maxlength="6"
aria-describedby="reference-help" required>
The pattern applies to the whole value, and required handles an empty field. A keyboard hint alone cannot enforce those rules. MDN's pattern documentation explains browser constraint validation. Give users visible instructions instead of relying on a pattern or a placeholder to explain the format.
Validate the same contract on the server. In your owned test environment, try an empty value, five digits, letters, and a longer pasted string. Confirm that rejection explains how to correct the field and preserves the user's other work. A browser-side check is useful feedback, not a boundary that makes unexpected requests impossible.
Use text for identifiers that must preserve leading zeros
An identifier can contain digits without being a quantity. Ask whether incrementing the value by one would make sense to a visitor. A project reference, postal code, or account identifier usually fails that test. The HTML Standard's number-input guidance explicitly distinguishes numbers from digit-based identifiers such as postal codes and credit card numbers.
For the six-digit reference above, keep 001234 as a string throughout the application. Inspect three places during QA: the field after blur, the request payload in a controlled submission, and the value returned on a later view. If the UI shows 1234, search for a numeric conversion in the input handler, schema, database mapping, or display formatter. Changing inputmode cannot restore zeros already removed by application code.
Do not apply the reference example to every postal address. Countries use different formats, including letters and spaces. If the form serves multiple countries, select rules from the address contract rather than assuming all postal codes are numeric or six characters long.
Handle decimal entry as a separate product decision
For a genuine numeric quantity, choose a suitable min, max, and step. For example, a measurement accepting hundredths might use:
<label for="length">Length in metres</label>
<input id="length" name="length" type="number"
min="0" step="0.01" inputmode="decimal" required>
The numeric control's validity rules still apply; inputmode="decimal" does not replace step or define your application's rounding policy. The HTML number-input specification describes the numeric constraints and leaves presentation choices to browsers.
Test the locales your form supports. Try a fractional value, an out-of-range value, and a value with more precision than allowed. Record what users can type and what the server receives. If your product needs locale-aware free-text parsing, design and test that parser explicitly. Avoid silently deleting commas or periods: a visitor's intended value can change substantially.
Debug the deployed field on a real phone
Inspect the rendered input after the application hydrates. A reusable component can omit inputmode, overwrite type, or reset a value on blur. Compare the final attributes and retained value with the field contract before changing CSS or adding key filters.
On each supported phone and browser, complete this short pass:
- Tap the field and enter every character used by a valid example.
- Paste a valid value with leading zeros, then edit it in the middle.
- Move to the next field and return; confirm the value remains intact.
- Trigger an error and correct it while the keyboard stays open.
- Reach the next action without a fixed footer covering the field or message.
If the keyboard's action label is misleading, consider enterkeyhint. It suggests labels or icons such as next, done, or search; it does not implement your form's navigation or submission handler. See the enterkeyhint reference, then test the resulting action rather than assuming the label proves it works.
Use the mobile website testing routine for layout and task coverage. Record device, operating system, browser, keyboard, locale, route, and build. A narrow desktop screenshot does not establish which keyboard a phone displayed.
Add HTML inputmode regression checks to CI
In a project already using Playwright Test, adapt this example to a deployed route you control. It checks the six-digit reference contract above without submitting the form:
import { test, expect } from "@playwright/test";
test("project reference keeps its mobile entry contract", async ({ page }) => {
const response = await page.goto("https://example.com/project-lookup");
expect(response?.status()).toBe(200);
const reference = page.getByRole("textbox", {
name: "Project reference", exact: true,
});
await expect(reference).toBeVisible();
await expect(reference).toHaveAttribute("type", "text");
await expect(reference).toHaveAttribute("inputmode", "numeric");
await expect(reference).toHaveAttribute("pattern", "[0-9]{6}");
await expect(reference).toHaveAttribute("required", "");
await reference.fill("001234");
await reference.press("Tab");
await expect(reference).toHaveValue("001234");
expect(await reference.evaluate((element) =>
(element as HTMLInputElement).checkValidity(),
)).toBe(true);
await reference.fill("12A456");
expect(await reference.evaluate((element) =>
(element as HTMLInputElement).checkValidity(),
)).toBe(false);
});
Playwright's web-first assertions retry visibility, attribute, and value checks. This test catches dropped hints, an accidental numeric control, and a lost leading zero on the tested blur path. Add separate tests for empty input, submission, server validation, and stored-value recovery in a safe fixture environment.
Playwright's device emulation configures properties such as viewport, user agent, and touch support. Treat the test above as DOM and application evidence; it does not demonstrate the layout or behavior of an operating-system keyboard. Keep real-phone results alongside it in your website regression testing record.
Check the surrounding form with Slop Audit
After validating mobile entry, run Slop Audit on the public form URL. When Browser Run capacity is available, its bounded audit collects form-label evidence, axe accessibility findings, sampled keyboard focus, and mobile and desktop screenshots. Those findings help you catch surrounding barriers before sharing a project or launching a signup flow.
Slop Audit does not select or verify an operating-system keyboard, run a dedicated inputmode rule, submit your form, or prove that identifiers survive backend storage. Use its report with your real-device entry results and focused regression tests. Review any skipped browser coverage, fix the observed barriers, and repeat the same route and field contract after deployment.