CKTIS / HTML
dirname: submit the text direction
Send a companion direction field without changing the text’s own field name.
Version: HTML Living Standard
Syntax
<input name="comment" dirname="comment.dir" dir="auto">On supported text-entry controls, dirname gives the nonempty name of an extra form entry containing directionality. The submitted companion value is ltr or rtl. It does not rename the text field, choose a directory or translate the value. Use a distinct companion name to avoid collisions in server processing.
The control’s direction comes from directionality rules, including an explicit direction or automatic detection. The attribute itself does not set that direction. A disabled or otherwise omitted control does not magically contribute useful submitted text. Treat both text and direction as client-provided data and validate them on the server.
The example sets Arabic and then Latin text in an automatically directed field. FormData contains a right-to-left companion first and a left-to-right companion second. This checks actual form serialization rather than guessing direction from the attribute string.
Examples
<!doctype html><meta charset="utf-8">
<form id="form"><label>Comment <input id="comment" name="comment" dirname="comment.dir" dir="auto"></label></form><output id="result"></output>
<script>
const form = document.querySelector('#form'), field = document.querySelector('#comment');
field.value = 'مرحبا'; const first = new FormData(form).get('comment.dir');
field.value = 'Hello'; const second = new FormData(form).get('comment.dir');
document.querySelector('#result').textContent = 'Arabic=' + first + '; Latin=' + second;
</script>Result
Arabic=rtl; Latin=ltr
The text field remains separately named; only the companion direction value is inspected.