treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Almanac

user-select

Last updated on:

The user-select property text unselectable.

.row-of-icons {
  -webkit-user-select: none;  /* Chrome all / Safari all */
  -moz-user-select: none;     /* Firefox all */
  -ms-user-select: none;      /* IE 10+ */

  /* No support for these yet, use at own risk */
  -o-user-select: none;
  user-select: none;          
}

This is useful in situations where you want to provide an easier/cleaner copy-paste experience for users (not have them accidentally text-select useless things, like icons or images). However it's a bit buggy. Firefox enforces the fact that any text matching that selector cannot be copied. WebKit still allows the text to be copied if you select elements around it. There is no spec for this property (non-standard) so it's unlikely to change until there is.

View Demo

More Information

Browser Support

Chrome Safari Firefox Opera IE Android iOS
Any Any Any Nope 10+ ? ?
View Comments

Comments

  1. Gabo
    Permalink to comment#

    Unfortunately it doesn’t seem to work for android devices… any advice ?

  2. Thanks for this trick. You forgot to add -ms-user-select into demo, didn’t You?

  3. Cupidvogel
    Permalink to comment#

    Although Firefox, Chrome and Safari support it all through, the implementations are slightly different, in Firefox, when one does mousedown on the given element and drags along it to copy text, the cursor remains default type (i.e if it was originally cross-hair it remains cross-hair during the drag, if it was pointer, it remains pointer), whereas in Chrome and Safari, the cursor turns crosshair during the drag, whatever be the original cursor type declaration for that element.

  4. David
    Permalink to comment#

    Also worth noting, -webkit-user-select causes major hang ups in the current version of safari. After including it on a basic page I was able to make safari freeze by clicking the mouse 6 times in a row.

    • David
      Permalink to comment#

      Update to my last statement. This only becomes noticeable when safari has around 7000 lines of text on a webpage to render

  5. Wk_of_Angmar
    Permalink to comment#

    In Firefox, this property value affects the element’s children and therefore you will not be able to select them either. Even manually overriding the children’s CSS properties will not allow you to select them.

    If you wish to manually override the children’s selection, then you must use the property value “-moz-none” instead of “none”.

  6. I’m curious in an app setting, would it be frowned upon to set this to none universally, and then enable it for areas that makes sense to be selectable (a body of copy, copy/paste interfaces, etc…) For me, it seems it could make the experience a little more seamless if someone Cmd/Ctrl-A’s inside the page, or drags too long unintentionally.

Leave a Comment

Use markdown or basic HTML and be nice.