css highlight text code example

Example 1: change highlight color html

::-moz-selection { /* Code for Firefox */
  color: red;
  background: yellow;
}

::selection {
  color: red;
  background: yellow;
}

Example 2: css text highlight

/*Term: css text highlight*/

/*This uses the element ::selection, which is as far as i
know only supported by Google Chrome so far. This is not
a problem though, since other browsers will simply keep
the regular highliting styles.*/

/*Example*/
::selection {
  background-color: #000; /*Highlight Color*/
  color: #fff; /*Text Color*/
}

Example 3: html highlight text

For HTML5: (with 'mark' tag)

<p>Do not forget to buy <mark>milk</mark> today.</p> 

In CSS file: (To customize highlight)

mark {
  background-color: yellow;
  color: black;
}

Example 4: css mark color

<style>
mark { 
  background-color: yellow;
  color: black;
}
</style>

<mark>Highlighted text!!</mark>

Example 5: how to highlight text in html

<mark>text</mark>

Example 6: how to highlight text in css

<body>
<p>The Math test is on <mark>Friday</mark>.</p>
</body>

Tags:

Css Example