CSS Trick: Click Once to Select All, Click Again to Select Normally

Will Boyd shared a neat CSS trick for controlling text selection behavior with a click.

  1. Apply user-select: all; to an element so that clicking it selects all of its content at once.
  2. When the user clicks a second time, let them select just parts of the text as usual.
  3. That second click isn't a real state change — it's a time-delayed @keyframes animation ending in forwards, triggered while the element is in :focus, that switches it to user-select: text;.

Boyd's article covers user-select in more depth, including additional use-cases and useful details.