Academic Block

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

Action
Windows
Mac
Linux
Select All
Ctrl + A
Cmd + A
Ctrl + A
Copy
Ctrl + C
Cmd + C
Ctrl + C
Cut
Ctrl + X
Cmd + X
Ctrl + X
Paste
Ctrl + V
Cmd + V
Ctrl + V
Find
Ctrl + F
Cmd + F
Ctrl + F
Undo
Ctrl + Z
Cmd + Z
Ctrl + Z
Redo
Ctrl + Y
Cmd + Shift + Z
Ctrl + Shift + Z
Save
Ctrl + S
Cmd + S
Ctrl + S

Browser Shortcuts

Action
Windows / Linux
Mac
New Tab
Ctrl + T
Cmd + T
Close Tab
Ctrl + W
Cmd + W
Reopen Closed Tab
Ctrl + Shift + T
Cmd + Shift + T
Refresh
F5 / Ctrl + R
Cmd + R
Hard Refresh
Ctrl + Shift + R
Cmd + Shift + R
Open DevTools
F12 / Ctrl + Shift + I
Cmd + Option + I
Full Screen
F11
Cmd + Ctrl + F

Useful Code Editor Shortcuts (VS Code)

Action
Windows / Linux
Mac
Toggle Comment
Ctrl + /
Cmd + /
Format Document
Shift + Alt + F
Shift + Option + F
Duplicate Line
Shift + Alt + ↓
Shift + Option + ↓
Delete Line
Ctrl + Shift + K
Cmd + Shift + K
Multi-cursor
Ctrl + Alt + ↓ / ↑
Option + Cmd + ↓ / ↑
Go to Matching Tag
Ctrl + Shift + \
Cmd + Shift + \
Emmet Expand
Tab (after abbreviation)
Tab

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

+ How can I jump between matching HTML tags in VS Code? >

Press Ctrl + Shift + \ (Windows/Linux) or Cmd + Shift + \ (Mac) to jump between the opening and closing tags of the current element.

+ What is the accesskey attribute used for? >

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).

+ How do I open browser DevTools quickly? >

Press F12 or Ctrl + Shift + I (Windows/Linux) / Cmd + Option + I (Mac) to open the developer tools.

+ How can I create a custom keyboard shortcut in JavaScript? >

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.

+ What is the Emmet shortcut to generate a full HTML5 document? >

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.

📝 HTML Code
👁️ Preview (Rendered HTML)

Click “Run Code” to see the result here.