JavaScript keycode space bar | Example code

  • by

JavaScript keycode of space bar is 32. These keycode values are only valid during in keydown and keyup events. On Mac, keypress events give you an completely different set of codes.

Must Read: JavaScript keycode list

Example spacebar key code JavaScript

HTML example code execute JS code after pressing space bar.

<!DOCTYPE html>

    document.body.onkeyup = function(e){
      if(e.keyCode == 32){




JavaScript keycode space bar

Do comment if you have any doubts and suggestions on this JS Keycode tutorial.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.