Home >Web Front-end >CSS Tutorial >How can I change the color of specific words in HTML text?

How can I change the color of specific words in HTML text?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-11 03:04:03457browse
<p>How can I change the color of specific words in HTML text?

<p>Changing Specific Word Colors in HTML Text

<p>In order to modify the colors of specific words within a block of text using HTML or inline CSS, follow these steps:

  1. Identify the target words you wish to highlight.
  2. Create elements around each target word.
  3. Assign unique classes or inline styles to each element, specifying the desired color value.
<p>HTML Example:

<p>
<p>In this example, the elements change the color of "January 30, 2011" to red (#ff0000) and "summer" to blue (#0000a0).

<p>CSS Example (Using Classes):


  
    
  
  
    <p>
      Enter the competition by 
      January 30, 2011
      and you could win up to $$$$ — including amazing 
      summer 
      trips!
    

<p>Here, we define two CSS classes, .date and .season, and assign them to the respective elements. This approach provides greater flexibility and allows for easier maintenance of styles.

The above is the detailed content of How can I change the color of specific words in HTML text?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn