The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Select specific words using CSS

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #201524

    Is there a way to select specific words in a paragraph using pure CSS.

    For example, if I wanted to style every word “apple” in a paragraph red, and every word “orange” in a paragraph orange, is there way to do that without PHP or javascript using pure CSS?



    CSS works by styling elements based on a set of rules.

    Unless the text is in element by itself with something that will differentiate it from other elements it’s not possible.

    What you use to differentiate it is up to you.

    Classes are the most obvious method, such as <span class="apple">Apple</span> but there are others, some more ID (that can only be used once) or broader, like data-attributes.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘CSS’ is closed to new topics and replies.