Since the contents of a textarea is taken as plain text, you cannot use span markup or any other markup there, and you cannot style its part other than the rest (except the first line or the first character using pseudo-elements).
However, at the plaintext level, bidirectional nesting can be enforced using control characters. Assuming that you set direction: rtl for the element as a whole (expecting users to enter data in the language from right to left), users can enter U + 202A LEFT-TO-RIGHT EMBEDDING to enter text from left to right, such as English or HTML markup, and then complete this by returning to right to left mode by typing U + 202C POP DIRECTIONAL FORMATTING.
Since most people do not know how to type these characters correctly, if at all, you may have buttons for them on the page:
<textarea id=msg name=msg rows=10 cols=40> </textarea> <br> <button type=button onclick="append('\u202A')">β</button> <button type=button onclick="append('\u202C')">β</button> <script> var msg = document.getElementById('msg'); function append(ch) { msg.innerHTML += ch; msg.focus(); } </script>
Jukka K. Korpela
source share