Codes to Highlight Text in HTML
- Highlight the text of an entire paragraph by changing the background color behind that paragraph. To do this, add the code "style="background-color:"" (without the outer quotes) in between the "p" and the closing bracket in the opening paragraph tag. It should look like this: <p style="background-color:">. You can choose any color you want to use and enter its name, hexadecimal code, or RGB value in between the colon and the second quotation mark. This will color the background behind the paragraph in a solid rectangle, no matter where each line ends or how much space is between each line of text.
- Depending on the background color you use, you may need to alter the text color as well to preserve readability or add more visual interest. To do this, add the code ";color:" and then the new font color in between the end of the background color name and the second quotation mark. For blue text on a green background, the code would look like this: <p style="background-color:green;color:blue">. You can also do this without altering the background color; the code to do that would look like this: <p style="color:blue">.
- You can use a span tag to change the font or background color, or both, of only part of a paragraph. Do this by surrounding the portion of the text you want to highlight with span tags, so it looks like the following: <span>text</span>. Add the same background color and/or font color code to the opening span tag that you would to the opening paragraph tag. The span tag will affect only the background immediately surrounding the chosen text; the color will not extend any further.
- An old method of highlighting text is using bgcolor="" in the same manner as style="background-color:." Though this method used to be widely used, it's being phased out as of 2011 and will no longer be supported on new browsers.