Can we disable keyboard key (Ctrl+A/Ctrl+C) with CSS, so that nobody can use select all shortcut using keyboard in my website?
-
What sense does that make? If I can't use the shortcuts, I select with the mouse and choose copy from the right click menu – Sven Bieder Dec 28 '12 at 16:24
-
1It might to better to explain what you are trying to stop people from copying. Most likely you can make it awkward but you can't make it impossible. – Popnoodles Dec 28 '12 at 16:25
-
1Honestly, if you don't want something to be copied; you may not want to put it on the internet. @popnoodles is right, there is no way to make it impossible. – Dec 28 '12 at 16:29
-
There is a hot topic about it on [webmasters stackexchange site](http://webmasters.stackexchange.com/questions/39392/how-to-disallow-selection-of-text-on-website/39396#39396). it could be useful. – agriboz Dec 28 '12 at 16:30
-
Why do you think CSS is the tool for the job? – BoltClock Dec 28 '12 at 16:39
-
I used java script also. But all I want disable keyboard shortcut when java script is disabled on browser. – Ovee Dec 28 '12 at 16:44
-
1CSS isn't some kind of JavaScript fallback, you know... – BoltClock Dec 28 '12 at 16:46
4 Answers
No, CSS cannot affect the browser's response to the keyboard. JavaScript can, but JavaScript can also be turned off.
In other words: you can't do that, and even if you do then you can't count on it.

- 428,835
- 81
- 738
- 806
-
I have disabled text selection by mouse with css, But cant do anything with keyboard short cut – Ovee Dec 28 '12 at 16:36
-
1As CSS affect browser's response to mouse, so I thought it may also work for keyboard as well – Ovee Dec 28 '12 at 17:16
Might not exactly be the functionality you're looking for, but if it's a small number of elements where you want to exclude a user from focusing, you can go into the html and add tabindex="-1"
on that element, which removes it from the keyboard focus list
<div tabindex="-1">element text</div>
and also use this css
.disable{
pointer-events:none;
background:#e9ecef;
}

- 143
- 3
- 13

- 1,775
- 1
- 11
- 24
-
1This is what I needed for a different problem, thank you! I was trying to prevent focus of elements while a form was in the process of submitting. – Daniel May 07 '23 at 03:33
Try this css
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
(from an answer to this question)
Though the original question was about selecting text with the mouse, this css seems to disable the ctrl+a / ctrl+c capability as well (at least in a quick test on a sample project)
-
I was also thinking about this. I wish this code could be modified for disabling keyboard keys as well. – Ovee Dec 28 '12 at 16:55
Not with CSS, however it's possible using JavaScript if the browser doesn't have the feature disabled.

- 6,764
- 28
- 36