Skip to main content
March 22, 2026 (Updated March 23, 2026)Noble Desktop/1 min read

Change the Text Selection Color with CSS

Master Custom Text Selection Styling with CSS

Browser Support Overview

CSS text selection styling is widely supported across modern browsers, with vendor prefixes required for complete compatibility.

CSS Selection Properties

::selection pseudo-element

The standard CSS pseudo-element for styling selected text. Works with background-color and color properties.

::-moz-selection

Mozilla Firefox specific vendor prefix. Required for Firefox compatibility in older versions.

::-webkit-selection

WebKit based browsers vendor prefix. Some older WebKit browsers may require this syntax.

Implementation Steps

1

Define Base Selection Style

Start with the standard ::selection pseudo-element and set your desired background-color and text color properties.

2

Add Vendor Prefixes

Include ::-moz-selection for Firefox compatibility, ensuring consistent appearance across all browsers.

3

Test Cross-Browser

Verify your selection styles work correctly in Chrome, Firefox, Safari, and Edge browsers.

4

Apply to Specific Elements

Target specific elements like paragraphs or headings for more granular control over selection appearance.

CSS Text Selection Styling

Pros
Enhances user experience and brand consistency
Simple implementation with CSS pseudo-elements
Wide browser support across modern browsers
Lightweight solution with no JavaScript required
Cons
Limited to background-color and color properties only
Requires vendor prefixes for full compatibility
Cannot style selection borders or other advanced properties
Some older browsers have inconsistent support

Implementation Checklist

0/5
Performance Best Practice

CSS selection styling has minimal performance impact since it only applies when users actively select text, making it safe to implement on any website.

Did you know that you can change a webpage’s text selection color to match your branding and design? In your CSS, use the ::selection selector with the background property. For example, to change the selection color to yellow, add the following CSS to your stylesheet:

::selection { background: #ffff00; } 
::-moz-selection { background: #ffff00; }

Note: The -moz adds support for Firefox.

Ct Change Selection Color

  

Key Takeaways

1CSS ::selection pseudo-element allows customization of text selection appearance
2Vendor prefixes like ::-moz-selection ensure cross-browser compatibility
3Only background-color and color properties are supported for selection styling
4Proper color contrast is essential for accessibility and readability
5Selection styles can be applied globally or to specific HTML elements
6Modern browsers widely support CSS text selection styling
7Implementation requires minimal code and has no performance impact
8Testing across multiple browsers ensures consistent user experience

RELATED ARTICLES