We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

event.charCode Redirect 1

« DOM Reference

This feature has been removed from the Web. Though some browsers may still support it, it is in the process of being dropped. Do not use it in old or new projects. Pages or Web apps using it may break at any time.


Returns the Unicode value of a character key pressed during a keypress event.

For constants equivalent to these numeric codes, see KeyEvent.


var value = event.charCode;
  • value is the Unicode value of the character key that was pressed.


<title>charCode example</title>

<script type="text/javascript">

function showChar(e)
alert("Key Pressed: " + String.fromCharCode(e.charCode) + "\n"
      + "charCode: " + e.charCode);


<body onkeypress="showChar(event);">
<p>Press any 'character' type key.</p>


In a keypress event, the Unicode value of the key pressed is stored in either the keyCode or charCode property, never both. If the key pressed generates a character (e.g. 'a'), charCode is set to the code of that character, respecting the letter case. (i.e. charCode takes into account whether the shift key is held down). Otherwise, the code of the pressed key is stored in keyCode.

When one or more modifier keys are pressed, there are some complex rules for charCode, see Gecko Keypress Event for the detail.

charCode is never set in the keydown and keyup events. In these cases, keyCode is set instead.

To get the code of the key regardless of whether it was stored in keyCode or charCode, query the which property.

Characters entered through an IME do not register through keyCode or charCode. Actually with the Chinese IME I'm using, entering the IME results in a keypress event with keyCode = 229 and no other key events fire until the IME exits (which may happen after multiple characters are inputted). I'm not sure if other IME's work this way.

For a list of the charCode values associated with particular keys, run the example in Gecko DOM Reference:Examples #Example 7: Displaying Event Object Constants and view the resulting HTML table.


Not part of any specification. You should use char instead. See KeyEvent.

Document Tags and Contributors

Last updated by: Sheppy,