Course contentsShow
← Web Development
Lesson 2523 of 2,98245. InternationalizationFree lesson

Form Controls and Input Direction

Style form inputs, labels, and validation messages appropriately for RTL languages.

Form Controls and Input Direction

You'll learn how to ensure forms and their feedback mechanisms work naturally in right-to-left (RTL) languages like Arabic and Hebrew.

Why Forms Need Special Attention in RTL

Forms are interactive elements where users read labels, enter text, and receive feedback. In RTL layouts, simply flipping the page direction isn't enough—form controls need careful styling to maintain usability. Think of it like adjusting a mirror: the reflection must be functionally correct, not just visually reversed.

Styling Inputs for RTL

When dir="rtl" is set, text inputs should align text to the right and display the cursor from that direction. Modern browsers handle this automatically for text directionality, but you need to consider:

  • Placeholders: Should align with the input's direction
  • Input padding: Icons or visual hints may need repositioning
  • Validation icons: Error/success indicators typically appear at the "end" of the field (left in RTL)
/* Logical properties work automatically with dir */
input {
  padding-inline-start: 1rem;
  padding-inline-end: 2.5rem; /* Room for icon */
}

.input-icon {
  inset-inline-end: 0.5rem; /* Appears at visual end */
}

Labels and Validation Messages

Labels should align naturally with their inputs. Validation messages often appear below fields—ensure any directional arrows or positioning respect the reading direction:

label {
  text-align: start; /* Adapts to dir */
}

.error-message {
  text-align: start;
  padding-inline-start: 0.5rem;
}

Key Takeaway: Use logical CSS properties (padding-inline-start, text-align: start, inset-inline-end) for form controls so labels, inputs, and validation messages automatically adapt to the document's text direction without hardcoded left/right values.