Top community members
All Wiki Articles Create Wiki Article

Welcome to Dirask IT community! ❤ 💻
We are community of people that helps each other.

If you think you have some skills to help others

help someone and become a part of our community - List Q & A

HTML - how to disable text selection?

0 contributions
17 points

Using HTML, JavaScript and CSS it is possible to remove text selection in following way.

1. Custom back compatible example

This approach removes text selecting (and not only) option from element by adding:

  • specific class (.disable-selection defined in example code)
  • unselectable="on" attribute - required by IE < 10 and Opera < 15
  • onselectstart="return false;" - alternative solution for Internet Explorer


  • some browsers still does not support user-select property (Can I use link here), so it is necessary to use prefixes for full capability.
  •  user-select proprty is not part of standard - it has working draft status for CSS4.
// ONLINE-RUNNER:browser;

<!doctype html>

    .disable-selection {
        -webkit-touch-callout: none; /* iOS Safari                         */
          -webkit-user-select: none; /* Safari                             */
           -khtml-user-select: none; /* Konqueror HTML                     */
             -moz-user-select: none; /* Firefox in the past (old versions) */
              -ms-user-select: none; /* Internet Explorer (>=10) / Edge    */
                  user-select: none; /* Currently supported:               */
                                     /* Chrome, Opera and Firefox          */

    div {
        margin: 10px;
        padding: 20px;

  <div class="disable-selection" 
       style="background: silver;" 
       onselectstart="return false;">
     This text is not selectable ...
  <div style="background: gold;">
     This text is selectable ...


0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more