Multicolor Text Highlighting in a Textarea or Text Input

No, you can’t do this in a textarea or text input. Any CSS text-related property will affect the whole text within the the textarea/input. You’ll need an editable element or document to achieve syntax highlighting. Example (works in all recent browsers; the last major browser not to support contenteditable was Firefox 2.0):

<code contenteditable="true">
  <span style="color: blue">var</span> foo = <span style="color: green">"bar"</span>;
</code>

Leave a Comment