How do I make text reverse direction in HTML?

Try this.

span {
  direction: rtl;
  unicode-bidi: bidi-override;
}
<span>who ate fourteen green apples and died.</span>

You can use bdo tag like so:

bdo[dir='rtl'] {
  color: red;
}
There once was a lady with pride,<br>
<bdo dir='rtl'>who ate fourteen green apples and died.</bdo><br> 
Within the lamented,<br>
<bdo dir='rtl'>the apple fermented</bdo><br> 
and made cider inside her insides.

Yes, this is possible using the combination of two Unicode control characters. Namely, the

  • 'RIGHT-TO-LEFT OVERRIDE' (U+202E)
  • 'LEFT-TO-RIGHT OVERRIDE' (U+202D)

Each override character makes the text that follows it flow in the corresponding direction.

These can be inserted into an document with the HTML entities &#x202E; and &#x202D;, or the decimal equivalents, &#8238; and &#8237;.

This allows you to write your example thus:

<p>
  There once was a young lady with pride,<br>
  &#x202e;who ate fourteen green apples and died.<br>
  &#x202d;Within the lamented,<br>
  &#x202e;the apple fermented<br>
  &#x202d;and made cider inside her insides.
</p>

I'm posting this HTML in now so you can see how it appears. You can observe the actual direction change by selecting parts of the text.

There once was a young lady with pride,
‮who ate fourteen green 123 apples and died.
‭Within the lamented,
‮the apple fermented
‭and made cider inside her insides.

If you wanted a true boustrephedon, where the letters forms are also backwards, and if you don't mind using CSS3 features, then you could use a CSS3 transform:

backward {
  display: inline-block;
  -moz-transform: scale(-1, 1);
  -webkit-transform: scale(-1, 1);
  transform: scale(-1, 1);
}
<p>
  There once was a lady with pride,<br>
  <backward>who ate fourteen green apples and died.</backward><br> Within the lamented,<br>
  <backward>the apple fermented</backward><br> and made cider inside her insides.
</p>

Tags:

Css