Localizing HTML Forms: Placeholders, Labels, Validation Messages, and Buttons

Localize HTML forms with <label> elements, translated hints and errors, and buttons that name the action in the reader’s language. This covers visible copy, accessible names, browser validation, and server responses; the main production caveat is that changing the page’s lang doesn’t guarantee the browser will show native validation messages in that language.

Keep a clear boundary between what people read and what your application submits. Translate “Email address” and “Subscribe,” but keep field names, action values, and error codes stable unless you’re intentionally changing the backend contract.

Decide What Gets Translated

Form content and the values that support it

SurfaceTranslateKeep stable or handle separately
Field names and hintsText inside <label>, visible help, and any placeholder copyid="email", for="email", name="email", and ID references in aria-describedby
Accessible namesThe human-readable value of aria-label when it’s genuinely neededThe ID references in aria-labelledby; translate the text they point to instead
Select options<option value="weekly">Chaque semaine</option>: translate Chaque semainevalue="weekly"; without an explicit value, the option’s text supplies the submitted value
ActionsText inside <button>, or the visible value of an existing <input type="submit">A named button’s machine value, such as name="intent" value="subscribe"
Validation and confirmationField errors, summary text, and success copyCodes such as EMAIL_REQUIRED, request field names, and validation rules

If a named <input type="submit"> doubles as a backend action selector, translating its value changes the value sent when that control submits the form. Switch to a <button> so the visible caption and machine value can vary independently.

Give Each Field a Label That Stays Visible

This markup can look tidy in a mockup, but typing removes the only visible identification for the email field. The button also couples the French caption to a backend parameter.

<form action="/fr/inscription" method="post">
  <input type="email" name="email"
         placeholder="Adresse e-mail" required>
  <input type="submit" name="intent" value="M’inscrire">
</form>

Some browser and assistive technology combinations may use the placeholder as a fallback accessible name, but it’s not a substitute for a persistent label. Submit the form with the button and inspect the request: the intent value is now localized rather than stable.

Never put a field’s only label, required instructions, or format constraints in its placeholder.

Render the form and its messages from the same locale catalog. Set lang="fr" on the page’s <html> element for a French page; if only the form is French, set lang="fr" on the form or its surrounding section instead.

<form id="subscribe-form" action="/fr/inscription" method="post"
      data-email-required="Saisissez votre adresse e-mail."
      data-email-invalid="Saisissez une adresse e-mail valide.">
  <div id="form-errors" tabindex="-1" hidden>
    <p>Vérifiez le champ suivant :</p>
    <a href="#email">Adresse e-mail</a>
  </div>

  <label for="email">Adresse e-mail (obligatoire)</label>
  <p id="email-hint">Exemple : nom@example.com</p>
  <input id="email" name="email" type="email" autocomplete="email"
         aria-describedby="email-hint email-error" required>
  <p id="email-error" hidden></p>

  <input type="hidden" name="intent" value="subscribe">
  <button type="submit">M’inscrire à la newsletter</button>
</form>

The for and id pair gives the input a persistent label and makes the label clickable. The format example stays visible after typing, while aria-describedby associates both the hint and any field error with the input. Because this form has only one action, the hidden intent is submitted regardless of whether submission comes from the button or another path; treat it as untrusted input on the server.

Choose Where Validation Messages Come From

Validation paths and who controls the message language

PathLanguage controlWhat to verify
Native browser validationThe browser supplies messages for constraints such as required and type="email". Don’t assume lang determines their language.Test with browser and OS language preferences that differ from the page locale.
Custom client validationYour locale catalog supplies text; input.validity supplies the reason.Check what happens on failure, on correction, and when JavaScript doesn’t load.
Server validationThe server selects messages using the request’s UI locale and stable error codes such as EMAIL_INVALID.Send a direct POST and verify that the response preserves the locale and shows an actionable error.

For the form above, load this browser JavaScript after the markup or from a deferred script. It keeps native validation in place until both custom event handlers are installed.

const form = document.querySelector('#subscribe-form');

if (form) {
  const email = form.querySelector('#email');
  const error = form.querySelector('#email-error');
  const summary = form.querySelector('#form-errors');

  function clearError() {
    email.removeAttribute('aria-invalid');
    error.textContent = '';
    error.hidden = true;
    summary.hidden = true;
  }

  email.addEventListener('input', clearError);

  form.addEventListener('submit', (event) => {
    clearError();
    if (email.validity.valid) return;

    event.preventDefault();
    error.textContent = email.validity.valueMissing
      ? form.dataset.emailRequired
      : form.dataset.emailInvalid;
    error.hidden = false;
    email.setAttribute('aria-invalid', 'true');
    summary.hidden = false;
    summary.focus();
  });

  form.noValidate = true;
}

noValidate skips automatic validation on submission; it doesn’t disable the validity checks. Without it, the browser can stop an invalid submission before the submit handler runs. Test that focus moves to the revealed summary, its link takes the reader back to the field, and editing clears both the stale message and aria-invalid. This handler covers the one field shown; if you add constrained controls, add validation and error rendering for those controls before letting the form submit.

Never rely on client-side validation to enforce server rules: every submitted value must be validated again on the server.

Render Server Errors in the Same Locale

Use the same locale source for the response as for the original form, such as the /fr/ route. When the server rejects the email after a POST, render the form again with the summary visible, the field marked invalid, and the rejected value preserved when safe. This is what the summary and field portion of that response can look like:

<div id="form-errors" tabindex="-1">
  <p>Vérifiez le champ suivant :</p>
  <a href="#email">Adresse e-mail</a>
</div>

<label for="email">Adresse e-mail (obligatoire)</label>
<p id="email-hint">Exemple : nom@example.com</p>
<input id="email" name="email" type="email" autocomplete="email"
       value="nom@" aria-invalid="true"
       aria-describedby="email-hint email-error" required>
<p id="email-error">Saisissez une adresse e-mail valide.</p>

Use your template engine’s HTML attribute escaping when inserting the submitted value; never concatenate raw input into markup. Render the error in the initial HTML so it’s available without JavaScript. Put the summary before the fields in reading order, and verify that the response clearly indicates failure rather than looking like a blank form or a success page.

Keep Layout Flexible Across Locales

Apply dir="rtl" on the document or localized section for a right-to-left interface. A field can have its own direction: dir="auto" is useful for free-form names or comments, while a field intended for conventional left-to-right email addresses can use dir="ltr" if that matches your product’s address policy.

.localized-form {
  display: grid;
  gap: 0.75rem;
  max-inline-size: 36rem;
}

.localized-form input:not([type="hidden"]),
.localized-form select {
  box-sizing: border-box;
  inline-size: 100%;
  min-inline-size: 0;
}

.localized-form button {
  justify-self: start;
  max-inline-size: 100%;
  padding-block: 0.65rem;
  padding-inline: 1rem;
  white-space: normal;
  overflow-wrap: anywhere;
}

Add class="localized-form" to the form to apply these rules. Logical properties follow the interface direction, and the button can grow taller instead of clipping a long translation. Check the result at a narrow viewport and with enlarged text, particularly when an error wraps onto multiple lines.

Test Locale Switching and Submission

  1. Open the French route with the browser configured for another language. Submit an empty field with and without JavaScript to compare the custom message with the native fallback.
  2. Submit nom@, then correct it to nom@example.com. Check focus, the summary link, the field description, and removal of aria-invalid.
  3. Inspect the successful request in the network panel. Confirm that the payload still contains email and intent=subscribe, and that the confirmation stays in French.
  4. Test server rejection separately with an invalid direct POST; a browser that blocks invalid input can otherwise hide a broken server response.

Use HTML Translate to compare rendered form markup across locales, then verify keyboard behavior and actual request payloads in the browser.

Common Mistakes and Troubleshooting

  • The visible label translates, but the spoken label doesn’t. An old aria-label can override the visible label in the accessible name. Remove it when <label> already supplies the right name.
  • Clicking the label doesn’t focus the field. A localized for no longer matches the input id, or the page has duplicate IDs. Keep each pair stable and unique.
  • The server receives the translated option text. The <option> has no explicit value. Supply a stable value and translate only its content.
  • The browser still shows a native pop-up. The custom handler may not have loaded, or form.noValidate wasn’t set after initialization. Check for script errors before assuming the locale catalog is wrong.
  • A corrected field still won’t submit. If you use setCustomValidity(), a nonempty message keeps the field invalid. Call setCustomValidity('') before rechecking the rule.
  • The form switches languages after a failed submit. The response is using a default locale. Resolve the locale from the localized action route or another explicit UI locale source and reuse it for the error render.

Localizing HTML Forms: Placeholders, Questions

Should every placeholder be translated?

Translate any instructional words in placeholder, but don’t translate literal user data or syntax. If the placeholder contains an example readers need to consult while typing, move that example into visible help.

Does changing lang change how a field validates?

Don’t treat it as a validation setting. lang declares the language of content; constraints such as required, type, and pattern still apply. Define locale-specific parsing on purpose where the accepted input actually differs.

Can the browser tell whether an email address exists?

No. type="email" applies an HTML syntax check, not a deliverability or ownership check. Use a server-side confirmation flow if ownership matters.

Should error text use aria-live?

Use a live region when an update needs to be announced without moving focus. If a failed submit already focuses an error summary, don’t make the same message an assertive announcement by default; test the chosen approach with assistive technology to catch silent or duplicate announcements.

What if a form has more than one submit action?

Give each <button type="submit"> the same parameter name and a distinct stable value, such as save or publish. Translate the button text, and test what happens when someone presses Enter in a field rather than explicitly selecting a button.

Should a localized form also translate what the user typed?

No. Preserve user-entered names, addresses, and comments as entered unless a clearly communicated processing rule requires normalization. Translate the surrounding <label>, hint, error, and confirmation instead.

Translate a file →