HTML Keyboard Shortcuts Get Certified
Keyboard Shortcuts for Windows, Mac, and Linux
Keyboard shortcuts significantly speed up coding, browsing, and system navigation. This page lists the most useful shortcuts for developers working with HTML across Windows, Mac, and Linux.
Navigation & Editing Shortcuts
Browser Shortcuts
Useful Code Editor Shortcuts (VS Code)
HTML-Related Code Examples
1. Using the accesskey Attribute
The accesskey attribute lets users activate an element with a keyboard shortcut.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>accesskey Demo</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
a, button { margin: 10px; padding: 10px 15px; display: inline-block; }
.note { margin-top: 20px; color: #555; }
</style>
</head>
<body>
<h2>accesskey Attribute Example</h2>
<a href="#home" accesskey="h">Home (Alt+H / Alt+Shift+H)</a>
<a href="#about" accesskey="a">About (Alt+A)</a>
<button accesskey="s" onclick="alert('Saved!')">Save (Alt+S)</button>
<p class="note">
Try the shortcuts:<br>
Windows/Linux → Alt + key<br>
Mac → Control + Option + key
</p>
</body>
</html>
2. Detecting Keyboard Events with JavaScript
Listen for key presses to create custom shortcuts in your web pages.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Keyboard Event Demo</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; background: #f5f5f5; }
#output {
margin-top: 20px;
padding: 15px;
background: white;
border: 1px solid #ddd;
min-height: 60px;
}
</style>
</head>
<body>
<h2>Keyboard Event Listener</h2>
<p>Press any key on your keyboard...</p>
<div id="output">Waiting for key press...</div>
<script>
const output = document.getElementById("output");
document.addEventListener("keydown", function(event) {
output.innerHTML =
"<strong>Key:</strong> " + event.key + "<br>" +
"<strong>Code:</strong> " + event.code + "<br>" +
"<strong>Ctrl:</strong> " + event.ctrlKey +
" | <strong>Alt:</strong> " + event.altKey +
" | <strong>Shift:</strong> " + event.shiftKey;
});
</script>
</body>
</html>
3. Custom Shortcut (Ctrl + S example)
Prevent the browser’s default save dialog and run your own action instead.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Custom Ctrl+S Shortcut</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
#status {
margin-top: 20px;
padding: 15px;
background: #e8f5e9;
border: 1px solid #4caf50;
}
</style>
</head>
<body>
<h2>Custom Keyboard Shortcut</h2>
<p>Press <strong>Ctrl + S</strong> (or Cmd + S on Mac) to trigger a custom save action.</p>
<div id="status">No shortcut pressed yet.</div>
<script>
document.addEventListener("keydown", function(e) {
// Detect Ctrl+S or Cmd+S
if ((e.ctrlKey || e.metaKey) && e.key === "s") {
e.preventDefault(); // stop browser save dialog
document.getElementById("status").innerHTML =
"✅ Custom Save triggered at " + new Date().toLocaleTimeString();
}
});
</script>
</body>
</html>
Web Resources on Keyboard Shortcuts
1. MDN : Keyboard Accessible Guide
2. MDN : KeyboardEvent Interface
3. MDN : keydown Event
4. MDN : HTML accesskey Attribute
Questions and Answers related to HTML Keyboard Shortcuts
Press Ctrl + Shift + \ (Windows/Linux) or Cmd + Shift + \ (Mac) to jump between the opening and closing tags of the current element.
The accesskey attribute defines a keyboard shortcut that activates or focuses an element. Usage varies by browser (usually Alt + key on Windows/Linux and Control + Option + key on Mac).
Press F12 or Ctrl + Shift + I (Windows/Linux) / Cmd + Option + I (Mac) to open the developer tools.
Listen for the keydown event, check event.ctrlKey / event.metaKey and the desired key, then call event.preventDefault() if you want to override the browser’s default behavior.
Type ! or html:5 and press Tab in an Emmet-enabled editor to expand a complete HTML5 boilerplate.
🧪 Test Your HTML Code
Edit the HTML code on the left and click “Run Code” to see the result on the right.
Click “Run Code” to see the result here.