Add a custom background color to selected text | Css

 p {
  ::selection {
    background: #0000ff;
  }
  ::-moz-selection {
    background: #0000ff;
  }
  ::-webkit-selection {
    background: #0000ff;
  }
}
 

AI Explanation

This CSS code is targeting the selection highlight color of text within `

` elements for different browsers. - `::selection`: This pseudo-element targets the selected text within the `

` element. It sets the background color of the selected text to blue (#0000ff) in browsers that support this pseudo-element. - `::-moz-selection`: This pseudo-element is specific to the Firefox browser and targets the selected text within the `

` element. It sets the background color of the selected text to blue (#0000ff) in Firefox. - `::-webkit-selection`: This pseudo-element is specific to WebKit-based browsers (such as Safari and Chrome) and targets the selected text within the `

` element. It sets the background color of the selected text to blue (#0000ff) in WebKit-based browsers. Overall, this CSS code ensures that the selected text within `

` elements will have a blue background color when highlighted, providing a consistent user experience across different browsers.