This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

The KeyboardEvent.charCode read-only property returns the Unicode value of a character key pressed during a keypress event.

For constants equivalent to these numeric codes, see KeyboardEvent.

Do not use this property anymore; it is deprecated. Use the KeyboardEvent.key property instead.


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.


Specification Status Comment
Document Object Model (DOM) Level 3 Events Specification
The definition of 'KeyboardEvent.charCode' in that specification.
Obsolete Initial definition; specified as deprecated

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic support
Chrome Full support 26Edge Full support YesFirefox Full support 3IE Full support 9Opera Full support 12.1Safari Full support 5.1WebView Android ? Chrome Android ? Edge Mobile Full support YesFirefox Android Full support YesOpera Android ? Safari iOS Full support 5.1Samsung Internet Android ?


Full support  
Full support
Compatibility unknown  
Compatibility unknown
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.

Document Tags and Contributors

Last updated by: Sheppy,