HTML: changing the color of specific words in a line of text

I have the following message (slightly modified):

"Enter the contest by January 30, 2011 and you can win $$$$ - including amazing summer trips!"

I currently have:

<p style="font-size:14px; color:#538b01; font-weight:bold; font-style:italic;"> 

formatting the text string, but want to change the color “January 30, 2011” to # FF0000 and “summer” to # 0000A0.

How to do this strictly with HTML or inline CSS?

+65
html css text colors inline
Jan 07 2018-11-11T00:
source share
10 answers
 <p style="font-size:14px; color:#538b01; font-weight:bold; font-style:italic;"> Enter the competition by <span style="color: #ff0000">January 30, 2011</span> and you could win up to $$$$ — including amazing <span style="color: #0000a0">summer</span> trips! </p> 

Or you can use CSS classes instead:

 <html> <head> <style type="text/css"> p { font-size:14px; color:#538b01; font-weight:bold; font-style:italic; } .date { color: #ff0000; } .season { /* OK, a bit contrived... */ color: #0000a0; } </style> </head> <body> <p> Enter the competition by <span class="date">January 30, 2011</span> and you could win up to $$$$ — including amazing <span class="season">summer</span> trips! </p> </body> </html> 
+82
Jan 07 2018-11-11T00:
source share

You can use the HTML5 <mark> :

 <p>Enter the competition by <mark class="red">January 30, 2011</mark> and you could win up to $$$$ — including amazing <mark class="blue">summer</mark> trips!</p> 

And use this in CSS:

 p { font-size:14px; color:#538b01; font-weight:bold; font-style:italic; } mark.red { color:#ff0000; background: none; } mark.blue { color:#0000A0; background: none; } 

The <mark> has a default background color ... at least in Chrome.

+33
Dec 14
source share
 <p style="font-size:14px; color:#538b01; font-weight:bold; font-style:italic;"> Enter the competition by <span style="color:#FF0000">January 30, 2011</span> and you could win up to $$$$ — including amazing <span style="color:#0000A0">summer</span> trips! </p> 

Span inline a elements, thus, do not break the flow of the paragraph, but only the style between the tags.

+31
Jan 07 2018-11-11T00:
source share

use spaces. ex) <span style='color: #FF0000;'>January 30, 2011</span>

+15
Jan 07 2018-11-11T00:
source share
 <font color="red">This is some text!</font> 

This worked better for me when I just wanted to change one word to red in a sentence.

+9
Sep 10 '17 at 3:01 on
source share

Think of this code as you like, according to your needs, can you choose the text? the paragraph will have the font or style that you need !:

 <head> <style> p{ color:#ff0000;font-family: "Times New Roman", Times, serif;} font{color:#000fff;background:#000000;font-size:225%;} b{color:green;} </style> </head> <body> <p>This is your <b>text. <font>Type</font></strong></b>what you like</p> </body> 
+1
Jun 19 '16 at 11:23
source share

You can use a longer boringer path

 <p style="font-size:14px; color:#538b01; font-weight:bold; font-style:italic;">Enter the competition by</p><p style="font-size:14px; color:#ff00; font-weight:bold; font-style:italic;">summer</p> 

you get meaning for the rest

0
Nov 17 '15 at 19:51
source share

You can also create a class:

<span class="mychangecolor"> I am in yellow color!!!!!!</span>

then in the css file do:

 .mychangecolor{ color:#ff5 /* it changes to yellow */ } 
0
Nov 20 '15 at 15:34
source share

I want to change the color to:

Biznesmen - Przedsiębiorca

Biznesmen - Przedsiębiorca -wanna red ..

0
Dec 10 '18 at 11:08
source share

If you are ready to use the library, Azle will make it easy. Just aim at the class and class instance of your text element. For example, if my block of text is inside an element with class "my_text" and this is the first instance of this class:

 az.style_word('my_text', 1, { "this_class" : "colored_word", "word" : "deploy", "color" : "red", "word_instance" : 2 }) 

The following shows how we can color each instance of a word, or target the 1st, 2nd, or 3rd instance of a word specifically:

enter image description here

Here is the fiddle

0
Jan 19 '19 at 19:59
source share



All Articles