A small piece of HTML can change what a visitor sees or how the browser understands a page. In this lesson, you will explore direction attribute: ltr, rtl, and auto using a short example that you can inspect and change.
The Idea in Plain English
The dir attribute controls base writing direction; auto lets the browser determine direction from strong characters within the element. It does not translate text or reverse strings.
You can test this using a small local HTML file. Change one part at a time and check the result in the browser before adding more code.
A Working Example
Read the sample once before copying it. Notice the element names and attribute values, then compare them with the explanation below.
<p dir="ltr">Hello, friends!</p>
<p dir="rtl">مرحبا بالأصدقاء</p>
<p dir="auto">A message whose direction is not known.</p>
What Each Part Does
- A paragraph keeps one idea together as readable text.
- The browser reads these lines in order and uses them to build the page or request.
- Changing the relevant value lets you test what this feature controls.
The paragraph alignment and punctuation order can follow the relevant writing direction.
Try It Yourself
Experiment with dir="auto" using both Latin and right-to-left text.
Common Beginner Mistakes
- Using CSS text-align as a replacement for correct bidirectional semantics.
- Changing several parts of the example at once, making it difficult to see which part caused a different result.
- Choosing a tag only because its default appearance looks right, without checking whether it describes the content correctly.
Key Takeaways
- The dir attribute controls base writing direction; auto lets the browser determine direction from strong characters within the element. It does not translate text or reverse strings.
- The paragraph alignment and punctuation order can follow the relevant writing direction.
- Test the markup in a browser, and check accessibility and real-world behavior where relevant.