How to prevent content selection with CSS?


How to prevent text / content selection from my web page with CSS?

This would be extremely useful for buttons, anchors, tags and other elements that could be selected without the user's interest ...

asked by anonymous 18.12.2013 / 17:42

2 answers


Using the following CSS rules for elements that can not be selected:

#seletor {
   -webkit-touch-callout: none;
   -webkit-user-select: none;
   -khtml-user-select: none;
   -moz-user-select: none;
   -ms-user-select: none;
   user-select: none;
18.12.2013 / 17:42
    <script type="text/javascript">
        function RemoveSelection() 
           {if (window.getSelection) {window.getSelection().removeAllRanges();}}
<body onmouseup="RemoveSelection();">
    Select some content on this page with the mouse!
13.04.2014 / 21:17