html · level 3 · unit 7 · lesson 3
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
<bdi> keeps words you do not control in their own bubble.
A page can be : an English list of winners might include an Arabic name. The browser works out each word's direction, but a right-to-left name next to numbers or punctuation can drag them to the wrong side.
When you show text you do not control, like usernames or reviews, wrap it in <bdi>, short for bidirectional . It keeps those words apart, so their direction cannot scramble the rest of the line.
For a box where people type, add dir="auto". The browser looks at the first real letter and picks the direction for them.
<h2>Top reviewers</h2>
<ul>
<li><bdi>Sam</bdi>: 12 reviews</li>
<li><bdi>ياسمين</bdi>: 9 reviews</li>
<li><bdi>Priya</bdi>: 7 reviews</li>
</ul>
<label for="nickname">Your nickname</label>
<input id="nickname" dir="auto"> Press show my page to see it here.
Without <bdi>, the colon and the 9 can jump to the wrong side of the Arabic name.
guess first
Which direction will this box use?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
<label for="search">Search the menu</label>
<input id="search" dir="auto" value="شاي">
your turn
Your turn. Isolate the names.
These names come from customers, so you cannot control them. Wrap each one in <bdi> by filling the blanks.
Press show my page to see it here.
- both names are isolatednot checked yet
- the second name is in a
<bdi>not checked yet
fix it
Typed Arabic starts on the wrong side. Can you fix it?
Press show my page to see it here.
- the box picks its own directionnot checked yet
- the Arabic runs right to leftnot checked yet
- This box forces one direction, whatever people type. Is that right for a comment box?
- Let the browser choose the direction from the first real letter.
- Change
dir="ltr"todir="auto"on line 2, then press run.
nailed it
mixed text stays in order. :D
- Bidirectional text mixes both directions in one line.
<bdi>isolates words you do not control.dir="auto"lets the browser choose for typed text.
new words in your collection
- bidirectional
- isolate
This lesson isn’t saved. A free account remembers every lesson you finish.