How can i style a sentences first word with only css

2815 views html
-4

<h2>hello world</h2>

Here, i want to styling first word "hello" without using any span or b tag or any JavaScript. just using style like h2:first-word{color:red}.

Is it possible? If possible how can i solve it?

answered question

2 Answers

12

You can't because there's no :first-word selector, only :first-letter and :first-line. You'll need insert span dynamically with JS if you don't control original HTML.

posted this
11

As far as i know it is not possible with pure css. There are some solutions with javascript.

Library: nthEverything Examples: Examples with ::first-word

posted this

Have an answer?

JD

Please login first before posting an answer.