Your Search Results

    ::selection Redirect 1

    Non-standard
    This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

    Summary

    The ::selection CSS pseudo-element applies rules to the portion of a document that has been highlighted (e.g., selected with the mouse or another pointing device) by the user.

    Only a small subset of CSS properties can be used in a rule using ::selection in its selector: color, background, background-color and text-shadow. Note that, in particular, background-image is ignored, like any other property.

    text-shadow in ::selection is supported by Chrome and Safari and will be supported in Firefox 17 and above.

    Though this pseudo-element was in drafts of CSS Selectors Level 3, it was removed during the Candidate Recommendation phase,  as it appeared that its behavior was under-specified, especially with nested elements, and interoperability wasn't achieved (based on discussion in the W3C Style mailing list).

    The ::selection pseudo-element currently isn't in any CSS module on the standard track. It should not be used in production environments.

    Examples

    Gecko is the only engine requiring the prefix. Due to the fact that the CSS parsing rules require dropping the whole rule when encountering an invalid pseudo-element, two separate rules must be written: ::-moz-selection, ::selection {...}. The rule would be dropped on non-Gecko browsers as ::-moz-selection is invalid on them.

    /* draw any selected text yellow on red background */
    ::-moz-selection { color: gold;  background: red; }
    ::selection      { color: gold;  background: red; } 
    
    /* draw selected text in a paragraph white on black */
    p::-moz-selection { color: white;  background: black; }
    p::selection      { color: white;  background: black; }

    Specifications

    The ::selection CSS pseudo-element was drafted for CSS Selectors Level 3 but removed before it reached the Recommendation status. Despite this, it's implemented in some browsers, which will probably retain experimental support for it.

    Right now, the ::selection CSS pseudo-element is not in any specification on the standard track.

    Browser compatibility

    Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
    Basic support 1 1.0 -moz 9 9.5 1.1
    Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
    Basic support ? ? ? ? ? ?

     

    Document Tags and Contributors

    Contributors to this page: Sheppy
    Last updated by: Sheppy,
    Hide Sidebar