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.
- Apply
user-select: all;to an element so that clicking it selects all of its content at once. - When the user clicks a second time, let them select just parts of the text as usual.
- That second click isn't a real state change — it's a time-delayed
@keyframesanimation ending inforwards, triggered while the element is in:focus, that switches it touser-select: text;.
Boyd's article covers user-select in more depth, including additional use-cases and useful details.



