Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to make a text unselectable in an HTML page?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 3.36k
    Comment on it

    Hey people!

    We developers, deal with HTML pages every second. Every  HTML UI essentially has some text elements. It is very easy for a user to double-click this text and select it. And this makes them look bad. To solve the same, CSS presents many standard-compliant ways. Here is an approach to make the text unselectable.

    HTML :

      Selectable text.
    <p class="noselect">
      Unselectable text.

    CSS :

    .noselect {
      -webkit-touch-callout: none; /* iOS Safari */
      -webkit-user-select: none;   /* Chrome/Safari/Opera */
      -khtml-user-select: none;    /* Konqueror */
      -moz-user-select: none;      /* Firefox */
      -ms-user-select: none;       /* Internet Explorer/Edge */
      user-select: none;           /* Non-prefixed version, currently
                                      not supported by any browser */

    In this solution, selection is disabled, but the user will still think of it as a selectable text because the cursor changes. To keep the cursor static, add the following line to your CSS :

    cursor: default;


    Note that the user-select is supported in all browsers at present with Internet Explorer 9 and earlier versions being the exceptions.

    Also, aside from this, there is no way to disable text selection using standard CSS.

    Keep Coding!


 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: