Home >Web Front-end >CSS Tutorial >How can I change the color of specific words within an HTML text string?
Changing Colors of Specific Words in HTML Text
To alter the color of specific words within a string of text in HTML, you can utilize inline CSS or CSS classes.
Inline CSS:
<p> Enter the competition by <br> <span> and you could win up to $$$$ — including amazing <br> <span> trips!<br></p><br>
This approach adds a span element around the words you want to color differently and applies the color style to that span.
CSS Classes:
Alternatively, you can define CSS classes:
<html><br> <head></p> <pre class="brush:php;toolbar:false"><style type="text/css"> p { font-size:14px; color:#538b01; font-weight:bold; font-style:italic; } .date { color: #ff0000; } .season { /* Contrived example... */ color: #0000a0; } </style>
<p> Enter the competition by <span>