The dirname attribute asks a form submission to include the direction of a text control in a separate named field.
HTML dirname: submit text direction beside the user's words
Use it in a concrete workflow
An international support form accepts a customer explanation in either writing direction. Recording that direction can help a downstream case viewer render the note as intended. The text itself still needs escaping, a visible label, and a server-side policy for storing language and direction metadata. Direction is not the same as language, and a reported direction is not proof of the author's identity or locale.
<form action="/support/cases" method="post">
<label for="case-explanation">Explain the damaged shipment</label>
<textarea id="case-explanation" name="explanation" dirname="explanation_dir" dir="auto" required></textarea>
<button type="submit">Send case</button>
</form>Behavior and ownership
The submitted fields include explanation and explanation_dir. The latter is a direction token, not a translation or a language tag; validate and store it alongside the note if the application needs it.
Performance and maintenance
The additional field adds little transfer cost. Handling mixed-direction text correctly across storage, logs, exports, and later rendering is the substantial implementation work.
Common Mistakes
- Do not infer the user's language from explanation_dir.
- Do not trust submitted direction metadata without validation.
- Do not insert the explanation into HTML without escaping.
