Not everyone uses a mouse to explore a website. Good HTML must also make sense through a keyboard or screen reader.
What You Need to Know
Mixed left-to-right and right-to-left text can make punctuation appear confusing. dir sets a direction, bdi isolates unknown-direction text, and bdo forces a direction. Choose the smallest change that fixes the reading order.
In this example: display mixed-direction names in a table.
Try the Example
Take a look at the example. We’ll explain the important lines right below it.
<p>Order number: <bdi>AB-123</bdi></p>
<p dir="rtl"><bdi>User123</bdi> submitted a message.</p>
<p>Each name keeps its own text-direction context.</p>
Let’s Read the Code
- dir: Dir controls text direction when left-to-right and right-to-left text is mixed.
- Read from the outside inward: the outer element describes the job, while the nested elements supply the information.
Read the named elements and attributes together. They explain how the browser connects this feature to the rest of the page.
What Happens in the Browser?
Try this with Tab and Shift+Tab. If you can, inspect the accessibility tree too; appearance alone does not tell the whole story.
Try a different way of reading. Read only the headings and labels, or navigate through links without looking at the rest of the page. If the page still makes sense, the underlying HTML is probably doing an important part of its job.
Your Turn
Use Tab and Shift+Tab to visit the controls, then read their labels aloud. Is the purpose of each one clear?
Common Beginner Mistakes
- Judging the page only by how it looks, without checking its meaning and keyboard behavior.
- Check the same result using both the browser and a keyboard, not only by looking at the screen.
Key Takeaways
- Mixed left-to-right and right-to-left text can make punctuation appear confusing.
- dir: Dir controls text direction when left-to-right and right-to-left text is mixed.
- Test the behavior you expect rather than trusting how the snippet looks in your editor.