Skip to content
Related Articles

Related Articles

Improve Article

HTML | DOM keyboardEvent charCode Property

  • Last Updated : 16 Jan, 2019

The keyboardEvent charCode property in HTML is used to return the unicode value of a character key pressed during a keypress event. It is a read-only property. The unicode character denotes the number of a character(e.g. the unicode for “A” is 65).



Return Value: It returns a number which represents the unicode number of the pressed character.


    <title>keyboardEvent charCode Property</title>
<body style="text-align: center;">
    <h1 style="color:green;">
            keyboardEvent charCode Property
        </h2> Input:
    <input type="text" placeholder="Press any key..">
    <p id="p"></p>
        // Adding a event listener function
        window.addEventListener("keypress", function(event) {
            var code = event.charCode;
            // Creating a span element
            var element = document.createElement("span");
            element.innerHTML = "Unicode value: " + code + "<br/>";
            // Appending span element to the paragraph
        }, true);


Supported Browsers: The browser supported by keyboardEvent charCode property are listed below:

  • Apple Safari
  • Google Chrome
  • Firefox
  • Opera
  • Internet Explorer 9.0

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :