9

I am using CSS 3.0 and it is complaining that the "user-select" property doesn't exist. Does anyone know what the appropriate substitute or replacement is?

MikeTWebb
  • 9,149
  • 25
  • 93
  • 132
  • 3
    What do you mean "it is complaining?" Are you trying to validate CSS3 through the CSS validation service? – Kyle Nov 16 '11 at 13:42

1 Answers1

20

user-select is back in the specification for CSS Basic User Interface Module Level 4. It is supported by most modern browsers (according to MDN), either prefixed or unprefixed.

#something {
    user-select: none;
    -ms-user-select: none;
    -moz-user-select: none;
    -webkit-user-select: none;
}

user-select was defined as part of User Interface for CSS3, which was later superseded by CSS3 Basic User Interface Module. However, the latter document does not include specification of user-select. After searching recently, I was unable to find any discussion on why it might have been removed from the spec.

See also: my answer on disabling text selection is not working in IE using jquery.

Andy E
  • 338,112
  • 86
  • 474
  • 445
  • @Andy...interesting stuff. However, I just tried "selectable" and the style sheet says it doesn't exist in CSS 3.0 either – MikeTWebb Nov 16 '11 at 13:48
  • @MikeTWebb: It's not a CSS property, so you have to apply it to elements in the HTML, e.g. `
    Can't select me
    `. Also, I made a minor mistake — it's actually `unselectable` :-)
    – Andy E Nov 16 '11 at 13:52
  • @Andy.....this is weird....maybe I'm doing something wrong but when I use this code, it says "unslectable is not a valid attribute for div"
    – MikeTWebb Nov 16 '11 at 13:58
  • @MikeTWebb: nope, you're not doing anything wrong. In an ironic twist to the plot, `unselectable` is not defined by the HTML spec either, so using it will invalidate your HTML. – Andy E Nov 16 '11 at 14:02
  • @Andy...hmmm. OK, so do you know if there is a way to disallow the user from selecting text in a div or textarea? There must be, one would think – MikeTWebb Nov 16 '11 at 14:11
  • @MikeTWebb: don't misunderstand, `unselectable` *will* work. You just have to make the hard choice of ignoring the errors resulting from it when validating your HTML. There are also JavaScript events, such as `onselect`, that you can bind to, but support for those is sketchy too. – Andy E Nov 16 '11 at 14:15
  • 1
    Old post, but there is now -ms-user-select as of IE10. – dmeglio May 04 '15 at 21:34
  • old post, but now chrome does work just fine with 'user-select' – roberto tomás May 27 '17 at 18:33
  • For anyone coming back in 2020, `user-select` works on Chrome, Firefox, and Edge (since Edge is using Blink). – Yuan-Hao Chiang Oct 07 '20 at 21:53