Files
30-seconds-of-code/snippets/disable-selection.md
2018-02-26 22:39:58 +05:30

1.1 KiB

Disable Selection

Makes the content unselectable.

HTML

<div>
  <p class="unselectable"> You can't select me! </p>
  <p> You can select me!! </p>
</div>

CSS

.unselectable {
  user-select: none;
}

Demo

You can't select me!

You can select me!!

<style> .snippet-demo__disable-selection{ user-select: none; } </style>

Explanation

user-select: none defines that the text cannot be selected.

Browser support

⚠️ Requires prefixes for full support and is not actually in any specification.