raven
raven

Reputation: 455

Styling certain text in textarea

Is it possible to only style certain text in a <textarea> element? I'm aware that you can't insert any other HTML tags within a <textarea> and would prefer not to resort to something hacky like creating a ghost or overlay element.

Use case: highlight any links inserted into the <textarea> with some font styles. It doesn't appear that the contentEditable really supports that, per this answer https://stackoverflow.com/a/1102242/849761 but as you can probably tell, I'm not a UI developer

Upvotes: 0

Views: 5043

Answers (1)

skyline3000
skyline3000

Reputation: 7913

No, it is not possible to style certain parts of text in a textarea element. You have to use contentEditable. The answer you've cited is from 2009 - contentEditable is supported by all major browsers now.

You'll need to write the logic to determine when a link has been entered or provide a way in the UI to add a link and use execCommand. But otherwise, the CSS is as simple as:

div[contenteditable="true"] a {
  /* styles */
}

Upvotes: 2

Related Questions