🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 169 (from laksa023)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

đź“„
INDEXABLE
âś…
CRAWLED
10 days ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.4 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript
Last Crawled2026-03-26 19:19:57 (10 days ago)
First Indexed2015-10-20 23:56:42 (10 years ago)
HTTP Status Code200
Meta Titlekeyboard - How do you tell if caps lock is on using JavaScript? - Stack Overflow
Meta Descriptionnull
Meta Canonicalnull
Boilerpipe Text
Yet another version, clear and simple, handles shifted capsLock, and not constrained to ascii I think: document . onkeypress = function ( e ) { e = e || window . event ; if (e. charCode === 0 || e. ctrlKey || document . onkeypress . punctuation . indexOf (e. charCode ) >= 0 ) return ; var s = String . fromCharCode (e. charCode ); // or e.keyCode for compatibility, but then have to handle MORE non-character keys var s2 = e. shiftKey ? s. toUpperCase () : s. toLowerCase (); var capsLockOn = (s2 !== s); document . getElementById ( 'capslockWarning' ). style . display = capsLockOn ? '' : 'none' ; } document . onkeypress . punctuation = [ 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 , 41 , 42 , 43 , 44 , 45 , 46 , 47 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 , 57 , 58 , 59 , 60 , 61 , 62 , 63 , 64 , 91 , 92 , 93 , 94 , 95 , 96 , 123 , 124 , 125 , 126 ]; Edit: Sense of capsLockOn was reversed, doh, fixed. Edit #2: After checking this out some more, I've made a few changes, a bit more detailed code unfortunately, but it handles more actions appropriately. Using e.charCode instead of e.keyCode and checking for 0 values skips a lot of non-character keypresses, without coding anything specific to a given language or charset. From my understanding, it's slightly less compatible, so older, non-mainstream, or mobile browsers may not behave as this code expects, but it's worth it, for my situation anyway. Checking against a list of known punctuation codes prevents them from being seen as false negatives, since they're not affected by caps lock. Without this, the caps lock indicator gets hidden when you type any of those punctuation characters. By specifying an excluded set, rather than an included one, it should be more compatible with extended characters. This is the ugliest, special-casiest bit, and there's some chance that non-Western languages have different enough punctuation and/or punctuation codes to be a problem, but again it's worth it IMO, at least for my situation.
Markdown
# ![site logo](https://stackoverflow.com/Content/Img/SE-logo75.png) By clicking “Sign up”, you agree to our [terms of service](https://stackoverflow.com/legal/terms-of-service/public) and acknowledge you have read our [privacy policy](https://stackoverflow.com/legal/privacy-policy). # OR Already have an account? [Log in](https://stackoverflow.com/users/login) [Skip to main content](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#content) [Stack Overflow](https://stackoverflow.com/) 1. [About](https://stackoverflow.co/) 2. Products 3. [For Teams](https://stackoverflow.co/internal/) 1. [Stack Internal Implement a knowledge platform layer to power your enterprise and AI tools.](https://stackoverflow.co/internal/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=stack-overflow-for-teams) 2. [Stack Data Licensing Get access to top-class technical expertise with trusted & attributed content.](https://stackoverflow.co/data-licensing/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=overflow-api) 3. [Stack Ads Connect your brand to the world’s most trusted technologist communities.](https://stackoverflow.co/advertising/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=stack-overflow-advertising) 4. [Releases Keep up-to-date on features we add to Stack Overflow and Stack Internal.](https://stackoverflow.blog/releases/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=releases) 5. [About the company](https://stackoverflow.co/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=about-the-company) [Visit the blog](https://stackoverflow.blog/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=top-nav&utm_content=blog) 1. ### [current community](https://stackoverflow.com/) - [Stack Overflow](https://stackoverflow.com/) [help](https://stackoverflow.com/help) [chat](https://chat.stackoverflow.com/?tab=explore) - [Meta Stack Overflow](https://meta.stackoverflow.com/) ### your communities [Sign up](https://stackoverflow.com/users/signup?ssrc=site_switcher&returnurl=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F348792%2Fhow-do-you-tell-if-caps-lock-is-on-using-javascript) or [log in](https://stackoverflow.com/users/login?ssrc=site_switcher&returnurl=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F348792%2Fhow-do-you-tell-if-caps-lock-is-on-using-javascript) to customize your list. ### [more stack exchange communities](https://stackexchange.com/sites) [company blog](https://stackoverflow.blog/) 2. [Log in](https://stackoverflow.com/users/login?ssrc=head&returnurl=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F348792%2Fhow-do-you-tell-if-caps-lock-is-on-using-javascript) 3. [Sign up](https://stackoverflow.com/users/signup?ssrc=head&returnurl=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F348792%2Fhow-do-you-tell-if-caps-lock-is-on-using-javascript) # Let's set up your homepage Select a few topics you're interested in: python javascript c\# reactjs java android html flutter c++ node.js typescript css r php angular next.js spring-boot machine-learning sql excel ios azure docker Or search from our full list: - javascript - python - java - c\# - php - android - html - jquery - c++ - css - ios - sql - mysql - r - reactjs - node.js - arrays - c - asp.net - json - python-3.x - .net - ruby-on-rails - sql-server - swift - django - angular - objective-c - excel - pandas - angularjs - regex - typescript - ruby - linux - ajax - iphone - vba - xml - laravel - spring - asp.net-mvc - database - wordpress - string - flutter - postgresql - mongodb - wpf - windows - xcode - amazon-web-services - bash - git - oracle-database - spring-boot - dataframe - azure - firebase - list - multithreading - docker - vb.net - react-native - eclipse - algorithm - powershell - macos - visual-studio - numpy - image - forms - scala - function - vue.js - performance - twitter-bootstrap - selenium - winforms - kotlin - loops - dart - express - sqlite - hibernate - matlab - python-2.7 - shell - rest - apache - entity-framework - android-studio - csv - maven - linq - qt - dictionary - unit-testing - asp.net-core - facebook - apache-spark - tensorflow - file - swing - class - unity-game-engine - sorting - date - authentication - go - symfony - t-sql - opencv - matplotlib - .htaccess - google-chrome - for-loop - datetime - codeigniter - perl - http - validation - sockets - google-maps - object - uitableview - xaml - oop - visual-studio-code - if-statement - cordova - ubuntu - web-services - email - android-layout - github - spring-mvc - elasticsearch - kubernetes - selenium-webdriver - ms-access - ggplot2 - user-interface - parsing - pointers - google-sheets - c++11 - security - machine-learning - google-apps-script - ruby-on-rails-3 - templates - flask - nginx - variables - exception - sql-server-2008 - gradle - debugging - tkinter - delphi - listview - jpa - asynchronous - haskell - web-scraping - jsp - pdf - ssl - amazon-s3 - google-cloud-platform - testing - xamarin - jenkins - wcf - batch-file - generics - npm - ionic-framework - network-programming - unix - recursion - google-app-engine - mongoose - visual-studio-2010 - .net-core - android-fragments - assembly - animation - math - svg - rust - session - intellij-idea - hadoop - join - curl - winapi - django-models - laravel-5 - next.js - url - heroku - http-redirect - tomcat - inheritance - google-cloud-firestore - webpack - gcc - image-processing - swiftui - keras - asp.net-mvc-4 - logging - dom - matrix - pyspark - actionscript-3 - button - post - optimization - firebase-realtime-database - jquery-ui - cocoa - xpath - iis - web - d3.js - javafx - firefox - xslt - internet-explorer - caching - select - asp.net-mvc-3 - opengl - events - asp.net-web-api - plot - dplyr - encryption - magento - stored-procedures - search - amazon-ec2 - ruby-on-rails-4 - memory - multidimensional-array - canvas - audio - random - jsf - vector - redux - cookies - input - facebook-graph-api - flash - indexing - xamarin.forms - arraylist - ipad - cocoa-touch - data-structures - video - model-view-controller - azure-devops - serialization - apache-kafka - jdbc - razor - woocommerce - awk - routes - mod-rewrite - servlets - excel-formula - beautifulsoup - filter - iframe - docker-compose - design-patterns - aws-lambda - text - visual-c++ - django-rest-framework - cakephp - mobile - android-intent - struct - react-hooks - methods - groovy - mvvm - lambda - ssh - time - checkbox - ecmascript-6 - grails - google-chrome-extension - installation - cmake - sharepoint - shiny - spring-security - jakarta-ee - plsql - android-recyclerview - core-data - types - sed - meteor - android-activity - bootstrap-4 - activerecord - websocket - replace - graph - group-by - scikit-learn - vim - file-upload - boost - junit - memory-management - sass - async-await - import - deep-learning - error-handling - eloquent - dynamic - dependency-injection - soap - silverlight - layout - apache-spark-sql - charts - deployment - browser - gridview - svn - while-loop - google-bigquery - vuejs2 - highcharts - dll - ffmpeg - view - foreach - makefile - plugins - redis - c\#-4.0 - reporting-services - jupyter-notebook - unicode - merge - reflection - https - server - google-maps-api-3 - twitter - oauth-2.0 - extjs - terminal - axios - pip - split - cmd - pytorch - encoding - django-views - collections - database-design - hash - netbeans - automation - data-binding - ember.js - build - tcp - pdo - sqlalchemy - apache-flex - entity-framework-core - concurrency - command-line - spring-data-jpa - printing - react-redux - java-8 - lua - html-table - neo4j - ansible - service - jestjs - mysqli - enums - parameters - flexbox - material-ui - module - promise - visual-studio-2012 - outlook - web-applications - uwp - firebase-authentication - webview - jquery-mobile - utf-8 - datatable - python-requests - parallel-processing - colors - drop-down-menu - scipy - scroll - tfs - hive - count - syntax - ms-word - twitter-bootstrap-3 - ssis - fonts - rxjs - constructor - file-io - google-analytics - paypal - three.js - powerbi - graphql - cassandra - discord - graphics - compiler-errors - gwt - react-router - socket.io - backbone.js - solr - memory-leaks - url-rewriting - datatables - nlp - terraform - oauth - datagridview - drupal - zend-framework - oracle11g - knockout.js - triggers - interface - neural-network - django-forms - casting - angular-material - jmeter - linked-list - google-api - path - timer - arduino - django-templates - orm - windows-phone-7 - proxy - directory - parse-platform - visual-studio-2015 - cron - conditional-statements - push-notification - functional-programming - primefaces - pagination - model - jar - xamarin.android - hyperlink - uiview - vbscript - visual-studio-2013 - google-cloud-functions - azure-active-directory - gitlab - jwt - download - swift3 - sql-server-2005 - process - rspec - configuration - pygame - properties - callback - combobox - windows-phone-8 - linux-kernel - safari - scrapy - emacs - permissions - x86 - clojure - scripting - raspberry-pi - scope - io - azure-functions - compilation - expo - responsive-design - mongodb-query - nhibernate - angularjs-directive - reference - request - bluetooth - binding - architecture - dns - playframework - 3d - pyqt - version-control - discord.js - doctrine-orm - package - f\# - rubygems - get - sql-server-2012 - autocomplete - tree - openssl - datepicker - kendo-ui - jackson - yii - controller - grep - nested - xamarin.ios - static - null - transactions - statistics - datagrid - active-directory - dockerfile - uiviewcontroller - webforms - sas - discord.py - computer-vision - phpmyadmin - notifications - duplicates - pycharm - mocking - youtube - yaml - nullpointerexception - menu - blazor - sum - plotly - bitmap - visual-studio-2008 - asp.net-mvc-5 - floating-point - css-selectors - yii2 - stl - android-listview - electron - jsf-2 - time-series - cryptography - ant - character-encoding - hashmap - stream - msbuild - asp.net-core-mvc - sdk - google-drive-api - jboss - selenium-chromedriver - joomla - devise - navigation - cuda - cors - frontend - anaconda - background - multiprocessing - binary - pyqt5 - camera - iterator - linq-to-sql - mariadb - onclick - android-jetpack-compose - ios7 - microsoft-graph-api - android-asynctask - rabbitmq - tabs - amazon-dynamodb - environment-variables - laravel-4 - uicollectionview - insert - linker - xsd - coldfusion - console - continuous-integration - upload - textview - ftp - opengl-es - operating-system - macros - mockito - localization - formatting - xml-parsing - json.net - type-conversion - vuejs3 - data.table - kivy - timestamp - integer - calendar - segmentation-fault - android-ndk - prolog - char - drag-and-drop - crash - jasmine - dependencies - automated-tests - geometry - azure-pipelines - fortran - android-gradle-plugin - itext - sprite-kit - mfc - header - attributes - nosql - firebase-cloud-messaging - format - nuxt.js - odoo - db2 - jquery-plugins - event-handling - julia - jenkins-pipeline - leaflet - annotations - flutter-layout - nestjs - keyboard - postman - arm - textbox - stripe-payments - visual-studio-2017 - gulp - libgdx - uikit - synchronization - timezone - azure-web-app-service - dom-events - wso2 - xampp - google-sheets-formula - crystal-reports - namespaces - aggregation-framework - android-emulator - uiscrollview - swagger - jvm - sequelize.js - com - chart.js - snowflake-cloud-data-platform - subprocess - geolocation - webdriver - html5-canvas - garbage-collection - sql-update - centos - dialog - concatenation - numbers - widget - qml - tuples - set - java-stream - mapreduce - ionic2 - smtp - windows-10 - android-edittext - rotation - nuget - spring-data - modal-dialog - radio-button - doctrine - http-headers - grid - sonarqube - lucene - xmlhttprequest - listbox - initialization - switch-statement - internationalization - components - boolean - apache-camel - google-play - gdb - serial-port - ios5 - ldap - return - youtube-api - pivot - eclipse-plugin - latex - frameworks - tags - containers - c++17 - subquery - github-actions - embedded - dataset - asp-classic - foreign-keys - label - uinavigationcontroller - delegates - copy - google-cloud-storage - struts2 - migration - protractor - base64 - uibutton - find - queue - sql-server-2008-r2 - arguments - composer-php - append - jaxb - stack - tailwind-css - zip - cucumber - autolayout - ide - entity-framework-6 - iteration - popup - r-markdown - windows-7 - vb6 - airflow - g++ - clang - ssl-certificate - hover - jqgrid - range - gmail Next You’ll be prompted to create an account to view your personalized homepage. 1. 1. [Home](https://stackoverflow.com/) 2. [Questions](https://stackoverflow.com/questions) 3. [AI Assist](https://stackoverflow.com/ai-assist) 4. [Tags](https://stackoverflow.com/tags) 5. [Challenges](https://stackoverflow.com/beta/challenges) 6. [Chat](https://chat.stackoverflow.com/?tab=explore) 7. [Articles](https://stackoverflow.blog/contributed?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=so-blog&utm_content=experiment-articles) 8. [Users](https://stackoverflow.com/users) 9. [Companies](https://stackoverflow.com/jobs/companies?so_medium=stackoverflow&so_source=SiteNav) 10. [Collectives]() 11. Communities for your favorite technologies. [Explore all Collectives](https://stackoverflow.com/collectives-all) 2. Stack Internal Stack Overflow for Teams is now called **Stack Internal**. Bring the best of human thought and AI automation together at your work. [Try for free](https://stackoverflowteams.com/teams/create/free/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=side-bar&utm_content=explore-teams) [Learn more](https://stackoverflow.co/internal/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=side-bar&utm_content=explore-teams) 3. [Stack Internal]() 4. Bring the best of human thought and AI automation together at your work. [Learn more](https://stackoverflow.co/internal/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=side-bar&utm_content=explore-teams-compact) ##### Collectives™ on Stack Overflow Find centralized, trusted content and collaborate around the technologies you use most. [Learn more about Collectives](https://stackoverflow.com/collectives) **Stack Internal** Knowledge at work Bring the best of human thought and AI automation together at your work. [Explore Stack Internal](https://stackoverflow.co/internal/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=side-bar&utm_content=explore-teams-compact-popover) # [How do you tell if caps lock is on using JavaScript?](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript) [Ask Question](https://stackoverflow.com/questions/ask) Asked 17 years, 1 month ago Modified [1 month ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript?lastactivity "2025-12-18 15:24:25Z") Viewed 136k times This question shows research effort; it is useful and clear 274 Save this question. Show activity on this post. How do you tell if caps lock is on using JavaScript? One caveat though: I did google it and the best solution I could find was to attach an `onkeypress` event to every input, then check each time if the letter pressed was uppercase, and if it was, then check if shift was also held down. If it wasn't, therefore caps lock must be on. This feels really dirty and just... *wasteful* - surely there's a better way than this? - [javascript](https://stackoverflow.com/questions/tagged/javascript "show questions tagged 'javascript'") - [keyboard](https://stackoverflow.com/questions/tagged/keyboard "show questions tagged 'keyboard'") - [capslock](https://stackoverflow.com/questions/tagged/capslock "show questions tagged 'capslock'") [Share](https://stackoverflow.com/q/348792 "Short permalink to this question") Share a link to this question Copy link [CC BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/ "The current license for this post: CC BY-SA 2.5") [Improve this question](https://stackoverflow.com/posts/348792/edit) Follow Follow this question to receive notifications [edited Dec 17, 2010 at 18:36](https://stackoverflow.com/posts/348792/revisions "show all edits to this post") [![Peter Mortensen's user avatar](https://i.sstatic.net/RIZKi.png?s=64)](https://stackoverflow.com/users/63550/peter-mortensen) [Peter Mortensen](https://stackoverflow.com/users/63550/peter-mortensen) 31\.2k2222 gold badges110110 silver badges134134 bronze badges asked Dec 8, 2008 at 6:22 [![nickf's user avatar](https://www.gravatar.com/avatar/f092dfd45793e9483281d4205b674823?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/9021/nickf) [nickf](https://stackoverflow.com/users/9021/nickf) 548k199199 gold badges660660 silver badges727727 bronze badges 9 - 223 BECAUSE WAY TOO MANY OF MY USERS FILL IN THEIR FORMS LIKE THIS. nickf – [nickf](https://stackoverflow.com/users/9021/nickf "547,922 reputation") 2009-05-22 08:40:27 +00:00 [Commented May 22, 2009 at 8:40](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment704319_348792) - 7 @nicf: If that's the reason, why don't you run a regexp on the input and ask them to stop shouting if there are too many upper case letters? some – [some](https://stackoverflow.com/users/36866/some "49,792 reputation") 2010-09-28 20:08:54 +00:00 [Commented Sep 28, 2010 at 20:08](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment4049373_348792) - 171 There's a much better reason to do this. If a user is entering a password, it would be very useful to warn them if their capslock is on. T Nguyen – [T Nguyen](https://stackoverflow.com/users/735374/t-nguyen "3,435 reputation") 2011-06-11 08:14:54 +00:00 [Commented Jun 11, 2011 at 8:14](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment7380721_348792) - 28 Seems like browsers should implement a "caps lock is on" warning when users type into `input type=password` fields (similar to email address validation for `input type=email` in chrome, etc.) nothingisnecessary – [nothingisnecessary](https://stackoverflow.com/users/403959/nothingisnecessary "6,271 reputation") 2014-09-02 19:59:08 +00:00 [Commented Sep 2, 2014 at 19:59](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment40046326_348792) - 9 Excellent question, but the accepted answer is 8 years old. The better response is [here](https://stackoverflow.com/a/34277417/2158270) Mac – [Mac](https://stackoverflow.com/users/2158270/mac "1,594 reputation") 2017-04-06 16:09:59 +00:00 [Commented Apr 6, 2017 at 16:09](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment73589576_348792) \| [Show **4** more comments](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript "Expand to show all comments on this post") ## 32 Answers 32 Sorted by: [Reset to default](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript?answertab=scoredesc#tab-top) 1 [2](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript?page=2&tab=scoredesc#tab-top "Go to page 2") [Next](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript?page=2&tab=scoredesc#tab-top "Go to page 2") This answer is useful 141 Save this answer. Show activity on this post. You can use a `KeyboardEvent` to detect numerous keys including the caps lock on most recent browsers. The [`getModifierState` function](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/getModifierState) will provide the state for: - Alt - AltGraph - CapsLock - Control - Fn (Android) - Meta - NumLock - OS (Windows & Linux) - ScrollLock - Shift [This demo](http://jsfiddle.net/Mottie/a6nhqvv0/) works in all major browsers including mobile ([caniuse](http://caniuse.com/#search=getModifierState)). ``` Copy ``` [Share](https://stackoverflow.com/a/34277417 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/34277417/edit) Follow Follow this answer to receive notifications [edited Apr 19, 2019 at 14:56](https://stackoverflow.com/posts/34277417/revisions "show all edits to this post") [![isherwood's user avatar](https://i.sstatic.net/PIsfn.jpg?s=64)](https://stackoverflow.com/users/1264804/isherwood) [isherwood](https://stackoverflow.com/users/1264804/isherwood) 61\.4k1616 gold badges122122 silver badges173173 bronze badges answered Dec 14, 2015 at 21:59 [![Mottie's user avatar](https://www.gravatar.com/avatar/9df80e51701bd6a791383150038d09e1?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/145346/mottie) [Mottie](https://stackoverflow.com/users/145346/mottie) 86\.8k3030 gold badges132132 silver badges248248 bronze badges Sign up to request clarification or add additional context in comments. ## 7 Comments Add a comment [![](https://i.sstatic.net/rYm0s.jpg?s=64)](https://stackoverflow.com/users/1773904/ian-clark) Ian Clark [Ian Clark](https://stackoverflow.com/users/1773904/ian-clark) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment65665345_34277417) I answered this on a dupe/similar question and was updated by another user that this now has Chrome support. I confirmed this, so now works across all major browsers - and should be the best solution to this question 2016-08-26T07:49:54.333Z+00:00 11 Reply - Copy link [![](https://www.gravatar.com/avatar/9df80e51701bd6a791383150038d09e1?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/145346/mottie) Mottie [Mottie](https://stackoverflow.com/users/145346/mottie) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment73359364_34277417) It's supported in Safari now. 2017-03-31T12:52:50.427Z+00:00 3 Reply - Copy link [![](https://i.sstatic.net/lk382.jpg?s=64)](https://stackoverflow.com/users/773259/spark) SparK [SparK](https://stackoverflow.com/users/773259/spark) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment93269261_34277417) And yet it detects the capslock press and can't get the general capslock state when user enters the form... 2018-11-07T13:17:44.01Z+00:00 4 Reply - Copy link [![](https://www.gravatar.com/avatar/0416bba2318890d7f06cdaaaaf38df4c?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/1091125/ashraf-slamang) Ashraf Slamang [Ashraf Slamang](https://stackoverflow.com/users/1091125/ashraf-slamang) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment94077674_34277417) This seems to work except when pressing the caps lock key into the *off* position. It doesn't pick up that input until the next key press. This was on Chrome for OS X. Not sure if this is something that spans across browsers and OSs. 2018-12-04T07:59:10.047Z+00:00 3 Reply - Copy link [![](https://lh6.googleusercontent.com/-UntWIVTVU8U/AAAAAAAAAAI/AAAAAAAAARo/EVZfCjTTWHs/s48-rj/photo.jpg)](https://stackoverflow.com/users/6024756/aniruddha-shevle) Aniruddha Shevle [Aniruddha Shevle](https://stackoverflow.com/users/6024756/aniruddha-shevle) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment117790072_34277417) @Mottie: Doesn't work on the actual android device on mobile browser\! 2021-03-15T06:24:53.517Z+00:00 1 Reply - Copy link Add a comment \| Show 2 more comments This answer is useful 128 Save this answer. Show activity on this post. In jQuery, ``` Copy ``` Avoid the mistake, like the backspace key, `s.toLowerCase() !== s` is needed. [Share](https://stackoverflow.com/a/896515 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/896515/edit) Follow Follow this answer to receive notifications [edited Jul 4, 2011 at 16:46](https://stackoverflow.com/posts/896515/revisions "show all edits to this post") [![Arthur P's user avatar](https://www.gravatar.com/avatar/85aa33cefdd16a704122e5d7cb9add34?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/795000/arthur-p) [Arthur P](https://stackoverflow.com/users/795000/arthur-p) 1,0701010 silver badges1616 bronze badges answered May 22, 2009 at 5:48 [![user110902's user avatar](https://www.gravatar.com/avatar/4c39d1f29db3e5f798f7a449632d0dd7?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/110902/user110902) [user110902](https://stackoverflow.com/users/110902/user110902) 1,34522 gold badges88 silver badges22 bronze badges ## 6 Comments Add a comment [![](https://i.sstatic.net/zJ4Pv.jpg?s=64)](https://stackoverflow.com/users/779092/shea) Shea [Shea](https://stackoverflow.com/users/779092/shea) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment9848501_896515) actually... fromCharCode eliminated the need for me to even check. however it should be noted that keydown and keypress give different charcodes, which was where I went wrong in the first place. 2011-11-07T21:24:46.543Z+00:00 5 Reply - Copy link user241244 user241244 [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment31829097_896515) \-1 bc this ONLY works if they have not pressed shift while CAPS is on. 2014-01-15T20:36:25.217Z+00:00 5 Reply - Copy link [![](https://i.sstatic.net/7GI8j.jpg?s=64)](https://stackoverflow.com/users/2798643/govinda-rajbhar) Govinda Rajbhar [Govinda Rajbhar](https://stackoverflow.com/users/2798643/govinda-rajbhar) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment57626928_896515) If anyone want to see a live example with bootstrap so you can view here [bootply.com/91792](http://www.bootply.com/91792) 2016-01-22T13:28:16.053Z+00:00 1 Reply - Copy link [![](https://i.sstatic.net/EJrNt.jpg?s=64)](https://stackoverflow.com/users/3692177/sebassbm) SebasSBM [SebasSBM](https://stackoverflow.com/users/3692177/sebassbm) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment89741738_896515) This answer was useful for me. I improved the conditional in [this answer](https://stackoverflow.com/a/51384804/3692177), due to the flaw mentioned by @D\_N, that it doesn't work while pressing shift. 2018-07-17T15:15:00.017Z+00:00 0 Reply - Copy link [![](https://i.sstatic.net/goZoI.png?s=64)](https://stackoverflow.com/users/4569045/taha-sultan-temuri) TAHA SULTAN TEMURI [TAHA SULTAN TEMURI](https://stackoverflow.com/users/4569045/taha-sultan-temuri) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment116365854_896515) but what if it is only on on document load? 2021-01-20T17:58:57.363Z+00:00 0 Reply - Copy link Add a comment \| Show 1 more comment This answer is useful 95 Save this answer. Show activity on this post. You can give it a try.. Added a working example. When focus is on input, turning on caps lock makes the led go red otherwise green. (Haven't tested on mac/linux) NOTE: Both versions are working for me. Thanks for constructive inputs in the comments. OLD VERSION: <https://jsbin.com/mahenes/edit?js,output> Also, here is a modified version (can someone test on mac and confirm) NEW VERSION: <https://jsbin.com/xiconuv/edit?js,output> **NEW VERSION:** ``` Copy ``` **OLD VERSION:** ``` Copy ``` For international characters, additional check can be added for the following keys as needed. You have to get the keycode range for characters you are interested in, may be by using a keymapping array which will hold all the valid use case keys you are addressing... uppercase A-Z or 'Ä', 'Ö', 'Ü', lowercase a-Z or 0-9 or 'ä', 'ö', 'ü' The above keys are just sample representation. [Share](https://stackoverflow.com/a/348802 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/348802/edit) Follow Follow this answer to receive notifications [edited Sep 9, 2020 at 15:51](https://stackoverflow.com/posts/348802/revisions "show all edits to this post") [![Mario Petrovic's user avatar](https://i.sstatic.net/FJ56r.jpg?s=64)](https://stackoverflow.com/users/3955557/mario-petrovic) [Mario Petrovic](https://stackoverflow.com/users/3955557/mario-petrovic) 8,4451616 gold badges4545 silver badges6666 bronze badges answered Dec 8, 2008 at 6:30 [![rajesh pillai's user avatar](https://www.gravatar.com/avatar/ae4bed5d9ddedbf6a0952e5186f853d5?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/34644/rajesh-pillai) [rajesh pillai](https://stackoverflow.com/users/34644/rajesh-pillai) 8,12677 gold badges4646 silver badges6060 bronze badges ## 9 Comments Add a comment user67627 user67627 [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment1779642_348802) It's possibly not the best implementation but when I wrote it I was trying to keep it simple. I think the only way you can really do it with the nastyness you need to cover for different browsers. 2009-12-10T10:29:43.043Z+00:00 1 Reply - Copy link [![](https://www.gravatar.com/avatar/0ae3534d3287105216151536db5a5213?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/1369663/tim) Tim [Tim](https://stackoverflow.com/users/1369663/tim) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment34516991_348802) I've found that using this with keydown (in chrome) causes all the codes to be picked up as caps. If I use keypress it works. 2014-03-26T12:25:58.25Z+00:00 2 Reply - Copy link [![](https://www.gravatar.com/avatar/bb430dc40c4648586562d2ef22c8557b?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/109392/awe) awe [awe](https://stackoverflow.com/users/109392/awe) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment49605038_348802) Finding each possible character combination for all international characters is doomed to miss out some cases. Use toUpper/Lower case methods instead to check casing. 2015-06-11T09:54:07.56Z+00:00 2 Reply - Copy link [![](https://www.gravatar.com/avatar/7636c7e4f43b4245fdacce7aef90ff85?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/856501/gamealchemist) GameAlchemist [GameAlchemist](https://stackoverflow.com/users/856501/gamealchemist) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment54801291_348802) Suprising that an answer completely false -confusing charcodes and ascii (!!!)- can get that much upvote. Nobody has ever checked ??? 2015-11-03T20:55:08.833Z+00:00 4 Reply - Copy link [![](https://www.gravatar.com/avatar/e79721e82929ea1f47aaf9660b61de8a?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/1600679/verism) verism [verism](https://stackoverflow.com/users/1600679/verism) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment58650546_348802) Note that [according to Mozilla](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/which), event.which has been removed from the Web standards. 2016-02-18T10:03:31.46Z+00:00 1 Reply - Copy link Add a comment \| Show 4 more comments This answer is useful 23 Save this answer. Show activity on this post. You can detect caps lock using "is letter uppercase and no shift pressed" using a keypress capture on the document. But then you better be sure that no other keypress handler pops the event bubble before it gets to the handler on the document. ``` Copy ``` You could grab the event during the capturing phase in browsers that support that, but it seems somewhat pointless to as it won't work on all browsers. I can't think of any other way of actually detecting caps lock status. The check is simple anyway and if non detectable characters were typed, well... then detecting wasn't necessary. There was [an article on 24 ways](http://24ways.org/2007/capturing-caps-lock) on this last year. Quite good, but lacks international character support (use `toUpperCase()` to get around that). [Share](https://stackoverflow.com/a/351326 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/351326/edit) Follow Follow this answer to receive notifications [edited Nov 7, 2018 at 13:21](https://stackoverflow.com/posts/351326/revisions "show all edits to this post") [![SparK's user avatar](https://i.sstatic.net/lk382.jpg?s=64)](https://stackoverflow.com/users/773259/spark) [SparK](https://stackoverflow.com/users/773259/spark) 5,21122 gold badges2626 silver badges3232 bronze badges answered Dec 8, 2008 at 23:29 [![Borgar's user avatar](https://www.gravatar.com/avatar/258cb92c16549c69fb987175bd52cdab?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/27388/borgar) [Borgar](https://stackoverflow.com/users/27388/borgar) 38\.9k55 gold badges4444 silver badges4242 bronze badges ## 4 Comments Add a comment [![](https://www.gravatar.com/avatar/3a48b9646b517ed4277d5d2b20f6c66e?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/1090395/mladen-janjetovic) Mladen Janjetovic [Mladen Janjetovic](https://stackoverflow.com/users/1090395/mladen-janjetovic) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment31157224_351326) This is actually what I was looking for. This works with Latin and Cyrillic strings. Thanks\! 2013-12-26T13:30:23.207Z+00:00 0 Reply - Copy link user241244 user241244 [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment31826855_351326) This works well, but keys like SPACE and numerals cue the warning. Know a (similarly concise/elegant) workaround? 2014-01-15T19:34:04.03Z+00:00 0 Reply - Copy link user241244 user241244 [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment31829171_351326) Also, it's good that you note the incompleteness, but it IS still incomplete. Not sure how to fix that with this method. 2014-01-15T20:38:25.79Z+00:00 1 Reply - Copy link [![](https://lh6.googleusercontent.com/-UntWIVTVU8U/AAAAAAAAAAI/AAAAAAAAARo/EVZfCjTTWHs/s48-rj/photo.jpg)](https://stackoverflow.com/users/6024756/aniruddha-shevle) Aniruddha Shevle [Aniruddha Shevle](https://stackoverflow.com/users/6024756/aniruddha-shevle) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment117976961_351326) @Bordar: Doesn't work on the actual android device on mobile browser\! 2021-03-22T04:56:11.86Z+00:00 0 Reply - Copy link Add a comment This answer is useful 12 Save this answer. Show activity on this post. Many existing answers will check for caps lock on when shift is not pressed but will not check for it if you press shift and get lowercase, or will check for that but will not also check for caps lock being off, or will check for that but will consider non-alpha keys as 'off'. Here is an adapted jQuery solution that will show a warning if an alpha key is pressed with caps (shift or no shift), will turn off the warning if an alpha key is pressed without caps, but will not turn the warning off or on when numbers or other keys are pressed. ``` Copy ``` [Share](https://stackoverflow.com/a/18905053 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/18905053/edit) Follow Follow this answer to receive notifications answered Sep 19, 2013 at 21:16 [![joshuahedlund's user avatar](https://www.gravatar.com/avatar/ea4fc86a806cf994d7c940cad1a43916?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/890308/joshuahedlund) [joshuahedlund](https://stackoverflow.com/users/890308/joshuahedlund) 1,78222 gold badges2020 silver badges2626 bronze badges ## Comments Add a comment This answer is useful 12 Save this answer. Show activity on this post. In JQuery. This covers the event handling in Firefox and will check for both unexpected uppercase and lowercase characters. This presupposes an `<input id="password" type="password" name="whatever"/>`element and a separate element with id '`capsLockWarning`' that has the warning we want to show (but is hidden otherwise). ``` Copy ``` [Share](https://stackoverflow.com/a/3815931 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/3815931/edit) Follow Follow this answer to receive notifications [edited Jan 15, 2014 at 9:48](https://stackoverflow.com/posts/3815931/revisions "show all edits to this post") user241244 answered Sep 28, 2010 at 18:33 [![Joe Liversedge's user avatar](https://www.gravatar.com/avatar/f6ca9607d1ba0c429959510b64469e8d?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/4552/joe-liversedge) [Joe Liversedge](https://stackoverflow.com/users/4552/joe-liversedge) 4,1942929 silver badges2020 bronze badges ## 3 Comments Add a comment user241244 user241244 [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment31804841_3815931) I'm not sure why, but this method does not work on the first keypress (tested only on Chrome). 2014-01-15T10:19:24.493Z+00:00 0 Reply - Copy link user241244 user241244 [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment31834119_3815931) Could it be the empty field hiding issue? I could not get that to work correctly, at least in Chrome. It automatically happens in many other browsers (at least in my version, below) because backspaces count and blank out the mssg. 2014-01-15T23:13:25.617Z+00:00 0 Reply - Copy link [![](https://www.gravatar.com/avatar/8c68413a839369d73dc9e9013faa0637?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/1366033/kylemit) KyleMit [KyleMit](https://stackoverflow.com/users/1366033/kylemit) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment84793819_3815931) **Note**: as you correctly utilized here, you need to use the `keypress` event to make use of different casings on input, because both [`keydown` and `keyup` will always return uppercase](https://stackoverflow.com/a/14944501/1366033). Consequently, this will not [fire the capslock key](https://stackoverflow.com/a/39716260/1366033) ...if you intended to combine with `e.originalEvent.getModifierState('CapsLock')` 2018-02-20T20:54:04.477Z+00:00 0 Reply - Copy link Add a comment This answer is useful 6 Save this answer. Show activity on this post. The top answers here didn't work for me for a couple of reasons (un-commented code with a dead link and an incomplete solution). So I spent a few hours trying everyone's out and getting the best I could: here's mine, including jQuery and non-jQuery. ## jQuery Note that jQuery normalizes the event object so some checks are missing. I've also narrowed it to all password fields (since that's the biggest reason to need it) and added a warning message. This has been tested in Chrome, Mozilla, Opera, and IE6-8. Stable and catches all capslock states EXCEPT when numbers or spaces are pressed. ``` Copy ``` ## Without jQuery Some of the other jQuery-less solutions lacked IE fallbacks. @Zappa patched it. ``` Copy ``` *** Note: Check out the solutions of @Borgar, @Joe Liversedge, and @Zappa, and the plugin developed by @Pavel Azanov, which I have not tried but is a good idea. If someone knows a way to expand the scope beyond A-Za-z, please edit away. Also, jQuery versions of this question are closed as duplicate, so that's why I'm posting both here. [Share](https://stackoverflow.com/a/21150216 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/21150216/edit) Follow Follow this answer to receive notifications answered Jan 15, 2014 at 23:08 user241244 ## 2 Comments Add a comment [![](https://www.gravatar.com/avatar/bb430dc40c4648586562d2ef22c8557b?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/109392/awe) awe [awe](https://stackoverflow.com/users/109392/awe) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment32768021_21150216) A good solution should always include support for letters outside the English letters A-Z. Any other solution is an insult to almost all non-english languages. 2014-02-10T12:34:47.613Z+00:00 5 Reply - Copy link [![](https://lh6.googleusercontent.com/-UntWIVTVU8U/AAAAAAAAAAI/AAAAAAAAARo/EVZfCjTTWHs/s48-rj/photo.jpg)](https://stackoverflow.com/users/6024756/aniruddha-shevle) Aniruddha Shevle [Aniruddha Shevle](https://stackoverflow.com/users/6024756/aniruddha-shevle) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment117977001_21150216) Doesn't work on the actual android device on mobile browser\! 2021-03-22T04:59:18.957Z+00:00 0 Reply - Copy link This answer is useful 6 Save this answer. Show activity on this post. We use `getModifierState` to check for caps lock, it's only a member of a mouse or keyboard event so we cannot use an `onfocus`. The most common two ways that the password field will gain focus is with a click in or a tab. We use `onclick` to check for a mouse click within the input, and we use `onkeyup` to detect a tab from the previous input field. If the password field is the only field on the page and is auto-focused then the event will not happen until the first key is released, which is ok but not ideal, you really want caps lock tool tips to display once the password field gains focus, but for most cases this solution works like a charm. HTML ``` Copy<input type="password" id="password" onclick="checkCapsLock(event)" onkeyup="checkCapsLock(event)" /> ``` JS ``` Copy ``` <https://codepen.io/anon/pen/KxJwjq> [Share](https://stackoverflow.com/a/52418434 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/52418434/edit) Follow Follow this answer to receive notifications [edited Sep 20, 2018 at 6:00](https://stackoverflow.com/posts/52418434/revisions "show all edits to this post") answered Sep 20, 2018 at 5:52 [![Ryan Marin's user avatar](https://www.gravatar.com/avatar/5ef3eed86384939b0e1970ba1a6840b1?s=64&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/10063563/ryan-marin) [Ryan Marin](https://stackoverflow.com/users/10063563/ryan-marin) 9411 silver badge55 bronze badges ## 3 Comments Add a comment [![](https://www.gravatar.com/avatar/f32388e98c0d8c87c2bc47104340b8f9?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/1408346/cameron-c) Cameron C [Cameron C](https://stackoverflow.com/users/1408346/cameron-c) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment91782164_52418434) Superb! Simple, concise, and flawless in my implementation. 2018-09-20T07:12:22.537Z+00:00 0 Reply - Copy link [![](https://www.gravatar.com/avatar/948b83a1d5d0d33b792afabea32e9add?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/2158270/mac) Mac [Mac](https://stackoverflow.com/users/2158270/mac) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment91806820_52418434) @Ryan: Thanks for the contribution! It's a good, clean example of code, though I'd like to point out your answer is basically the same as [Mottie's reply](https://stackoverflow.com/a/34277417/2158270) from 2015, where you both employ `event.getModifierState("CapsLock").` 2018-09-20T19:01:13.32Z+00:00 1 Reply - Copy link [![](https://lh6.googleusercontent.com/-UntWIVTVU8U/AAAAAAAAAAI/AAAAAAAAARo/EVZfCjTTWHs/s48-rj/photo.jpg)](https://stackoverflow.com/users/6024756/aniruddha-shevle) Aniruddha Shevle [Aniruddha Shevle](https://stackoverflow.com/users/6024756/aniruddha-shevle) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment117790042_52418434) @Ryan: Doesn't work on the actual android device on mobile browser\! 2021-03-15T06:22:14.27Z+00:00 0 Reply - Copy link Add a comment This answer is useful 5 Save this answer. Show activity on this post. I know this is an old topic but thought I would feed back in case it helps others. None of the answers to the question seem to work in IE8. I did however find this code that works in IE8. (Havent tested anything below IE8 yet). This can be easily modified for jQuery if required. ``` Copy ``` And the function is called through the onkeypress event like this: ``` Copy ``` [Share](https://stackoverflow.com/a/8222652 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/8222652/edit) Follow Follow this answer to receive notifications answered Nov 22, 2011 at 6:02 [![Zappa's user avatar](https://www.gravatar.com/avatar/6a36dfad414f8cb2e48f3a9fff0553ec?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/1040842/zappa) [Zappa](https://stackoverflow.com/users/1040842/zappa) 49511 gold badge55 silver badges1414 bronze badges ## 1 Comment Add a comment user241244 user241244 [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment31834149_8222652) Thanks for the IE8- fix. Incorporated it in my reworked answer (below). This is solid, though. 2014-01-15T23:14:31.477Z+00:00 0 Reply - Copy link This answer is useful 5 Save this answer. Show activity on this post. This is a solution that, in addition to checking state when writing, also toggles the warning message each time the `Caps Lock` key is pressed (with some limitations). It also supports non-english letters outside the A-Z range, as it checks the string character against `toUpperCase()` and `toLowerCase()` instead of checking against character range. ``` Copy ``` ``` Copy ``` Run code snippet Edit code snippet Hide Results Copy to answer Expand Note that observing caps lock toggling is only useful if we know the state of the caps lock before the `Caps Lock` key is pressed. The current caps lock state is kept with a `caps` JavaScript property on the password element. This is set the first time we have a validation of the caps lock state when the user presses a letter that can be upper or lower case. If the window loses focus, we can no longer observe caps lock toggling, so we need to reset to an unknown state. [Share](https://stackoverflow.com/a/21679062 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/21679062/edit) Follow Follow this answer to receive notifications [edited Sep 8, 2016 at 10:22](https://stackoverflow.com/posts/21679062/revisions "show all edits to this post") answered Feb 10, 2014 at 13:52 [![awe's user avatar](https://www.gravatar.com/avatar/bb430dc40c4648586562d2ef22c8557b?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/109392/awe) [awe](https://stackoverflow.com/users/109392/awe) 22\.5k77 gold badges8282 silver badges9393 bronze badges ## 1 Comment Add a comment [![](https://www.gravatar.com/avatar/5c9d0ecbe3045579b72f96744c62735c?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/1157054/ajedi32) Ajedi32 [Ajedi32](https://stackoverflow.com/users/1157054/ajedi32) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment49571178_21679062) Good idea. If you're going to show a warning to the user that caps lock is on it's probably a good idea to turn that warning off immediately when the caps lock is disabled, otherwise you might confuse the user. 2015-06-10T14:22:20.523Z+00:00 2 Reply - Copy link This answer is useful 4 Save this answer. Show activity on this post. A variable that shows caps lock state: ``` Copy ``` works on all browsers =\> [canIUse](http://caniuse.com/#search=getModifierState) [Share](https://stackoverflow.com/a/45189632 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/45189632/edit) Follow Follow this answer to receive notifications answered Jul 19, 2017 at 11:47 [![Alice Rocheman's user avatar](https://i.sstatic.net/42qFO.jpg?s=64)](https://stackoverflow.com/users/3422031/alice-rocheman) [Alice Rocheman](https://stackoverflow.com/users/3422031/alice-rocheman) 1,00611 gold badge88 silver badges88 bronze badges ## 1 Comment Add a comment [![](https://www.gravatar.com/avatar/08cf7d24d2021e14913a9cd067279f2a?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/717833/eon) eon [eon](https://stackoverflow.com/users/717833/eon) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment83334181_45189632) Upvoted for giving an up-to-date answer to an old question. You might want to add something like a headline saying something like "For modern browsers (2017-\>) try this" or "Update for 2017" 2018-01-09T21:43:22.497Z+00:00 1 Reply - Copy link This answer is useful 3 Save this answer. Show activity on this post. Recently there was a [similar question](https://ru.stackoverflow.com/questions/179050/javascript-%D0%B2%D0%BA%D0%BB%D1%8E%D1%87%D0%B5%D0%BD-%D0%BB%D0%B8-caps-lock-%D0%B8%D0%BB%D0%B8-%D0%BD%D0%B5%D1%82-%D0%BD%D0%B0-%D1%81%D0%B0%D0%B9%D1%82%D0%B5) on hashcode.com, and I created a jQuery plugin to deal with it. It also supports the recognition of caps lock on numbers. (On the standard German keyboard layout caps lock has effect on numbers). You can check the latest version here: [jquery.capsChecker](https://github.com/azanov/jquery.capsChecker) [Share](https://stackoverflow.com/a/14113715 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/14113715/edit) Follow Follow this answer to receive notifications [edited Apr 12, 2017 at 7:33](https://stackoverflow.com/posts/14113715/revisions "show all edits to this post") [![Community's user avatar](https://www.gravatar.com/avatar/a007be5a61f6aa8f3e85ae2fc18dd66e?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/-1/community) [Community](https://stackoverflow.com/users/-1/community)Bot 111 silver badge answered Jan 1, 2013 at 20:00 [![Pavel Azanov's user avatar](https://i.sstatic.net/fqdHx.jpg?s=64)](https://stackoverflow.com/users/1941460/pavel-azanov) [Pavel Azanov](https://stackoverflow.com/users/1941460/pavel-azanov) 19811 silver badge1212 bronze badges ## Comments Add a comment This answer is useful 3 Save this answer. Show activity on this post. **For jQuery with twitter bootstrap** Check caps locked for the following characters: uppercase A-Z or 'Ä', 'Ö', 'Ü', '!', '"', '§', '\$', '%', '&', '/', '(', ')', '=', ':', ';', '\*', ''' lowercase a-Z or 0-9 or 'ä', 'ö', 'ü', '.', ',', '+', '\#' ``` Copy ``` [**live demo on jsfiddle**](http://jsfiddle.net/05kofe9q/) [Share](https://stackoverflow.com/a/25719879 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/25719879/edit) Follow Follow this answer to receive notifications [edited Sep 8, 2014 at 9:14](https://stackoverflow.com/posts/25719879/revisions "show all edits to this post") [![Community's user avatar](https://www.gravatar.com/avatar/a007be5a61f6aa8f3e85ae2fc18dd66e?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/-1/community) [Community](https://stackoverflow.com/users/-1/community)Bot 111 silver badge answered Sep 8, 2014 at 8:12 [![ramiz4's user avatar](https://i.sstatic.net/a7RTf.jpg?s=64)](https://stackoverflow.com/users/3466032/ramiz4) [ramiz4](https://stackoverflow.com/users/3466032/ramiz4) 8133 bronze badges ## 1 Comment Add a comment [![](https://lh6.googleusercontent.com/-UntWIVTVU8U/AAAAAAAAAAI/AAAAAAAAARo/EVZfCjTTWHs/s48-rj/photo.jpg)](https://stackoverflow.com/users/6024756/aniruddha-shevle) Aniruddha Shevle [Aniruddha Shevle](https://stackoverflow.com/users/6024756/aniruddha-shevle) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment117977074_25719879) Doesn't work on the actual android device on mobile browser\! 2021-03-22T05:07:00.957Z+00:00 0 Reply - Copy link This answer is useful 2 Save this answer. Show activity on this post. This code detects caps lock no matter the case or if the shift key is pressed: ``` Copy ``` [Share](https://stackoverflow.com/a/21289237 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/21289237/edit) Follow Follow this answer to receive notifications [edited Mar 5, 2014 at 13:07](https://stackoverflow.com/posts/21289237/revisions "show all edits to this post") answered Jan 22, 2014 at 17:01 [![formixian's user avatar](https://i.sstatic.net/kQeSR.jpg?s=64)](https://stackoverflow.com/users/780036/formixian) [formixian](https://stackoverflow.com/users/780036/formixian) 1,5591616 silver badges2525 bronze badges ## 1 Comment Add a comment [![](https://i.sstatic.net/IaUa8.jpg?s=64)](https://stackoverflow.com/users/2147704/adrian-rosca) Adrian Rosca [Adrian Rosca](https://stackoverflow.com/users/2147704/adrian-rosca) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment41490787_21289237) This causes space and backspace to detect as upper case on Firefox. 2014-10-17T10:08:35.64Z+00:00 0 Reply - Copy link This answer is useful 2 Save this answer. Show activity on this post. I wrote a library called [capsLock](https://github.com/aaditmshah/capsLock) which does exactly what you want it to do. Just include it on your web pages: ``` Copy<script src="https://rawgit.com/aaditmshah/capsLock/master/capsLock.js"></script> ``` Then use it as follows: ``` Copy ``` See the demo: <http://jsfiddle.net/3EXMd/> The status is updated when you press the Caps Lock key. It only uses the Shift key hack to determine the correct status of the Caps Lock key. Initially the status is `false`. So beware. [Share](https://stackoverflow.com/a/24038811 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/24038811/edit) Follow Follow this answer to receive notifications answered Jun 4, 2014 at 13:29 [![Aadit M Shah's user avatar](https://www.gravatar.com/avatar/835bdcdab3e4bf466f0d59f809c50035?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/783743/aadit-m-shah) [Aadit M Shah](https://stackoverflow.com/users/783743/aadit-m-shah) 74\.5k3131 gold badges177177 silver badges312312 bronze badges ## 2 Comments Add a comment [![](https://www.gravatar.com/avatar/966ab7e95746a94355b5f20007b0da9e?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/2087263/ric) Ric [Ric](https://stackoverflow.com/users/2087263/ric) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment39357082_24038811) This is a really ingenious solution. But it has the bug that if the Caps Lock is on when the page gains focus, the "capslock" object starts with the incorrect state (off). 2014-08-12T08:43:32.64Z+00:00 0 Reply - Copy link [![](https://www.gravatar.com/avatar/835bdcdab3e4bf466f0d59f809c50035?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/783743/aadit-m-shah) Aadit M Shah [Aadit M Shah](https://stackoverflow.com/users/783743/aadit-m-shah) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment39360598_24038811) Indeed it starts with an incorrect state. However when you press any key it automatically corrects its state. If you can figure out a way to set it to the correct state when the page gains focus then I would be more than happy to merge your code. 2014-08-12T10:19:06.997Z+00:00 0 Reply - Copy link This answer is useful 2 Save this answer. Show activity on this post. Yet another version, clear and simple, handles shifted capsLock, and not constrained to ascii I think: ``` Copy ``` **Edit:** Sense of capsLockOn was reversed, doh, fixed. **Edit \#2:** After checking this out some more, I've made a few changes, a bit more detailed code unfortunately, but it handles more actions appropriately. - Using e.charCode instead of e.keyCode and checking for 0 values skips a lot of non-character keypresses, without coding anything specific to a given language or charset. From my understanding, it's slightly less compatible, so older, non-mainstream, or mobile browsers may not behave as this code expects, but it's worth it, for my situation anyway. - Checking against a list of known punctuation codes prevents them from being seen as false negatives, since they're not affected by caps lock. Without this, the caps lock indicator gets hidden when you type any of those punctuation characters. By specifying an excluded set, rather than an included one, it should be more compatible with extended characters. This is the ugliest, special-casiest bit, and there's some chance that non-Western languages have different enough punctuation and/or punctuation codes to be a problem, but again it's worth it IMO, at least for my situation. [Share](https://stackoverflow.com/a/24782909 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/24782909/edit) Follow Follow this answer to receive notifications [edited Jul 17, 2014 at 11:26](https://stackoverflow.com/posts/24782909/revisions "show all edits to this post") answered Jul 16, 2014 at 14:05 [![enigment's user avatar](https://www.gravatar.com/avatar/7b14ae81a42716356eae301097d2bfc4?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/736006/enigment) [enigment](https://stackoverflow.com/users/736006/enigment) 3,73677 gold badges3434 silver badges3636 bronze badges ## Comments Add a comment This answer is useful 2 Save this answer. Show activity on this post. [This jQuery-based answer](https://stackoverflow.com/a/896515/3692177) posted by @user110902 was useful for me. However, I improved it a little to prevent a flaw mentioned in @B\_N 's comment: it failed detecting CapsLock while you press Shift: ``` Copy ``` Like this, it will work even while pressing Shift. [Share](https://stackoverflow.com/a/51384804 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/51384804/edit) Follow Follow this answer to receive notifications answered Jul 17, 2018 at 15:08 [![SebasSBM's user avatar](https://i.sstatic.net/EJrNt.jpg?s=64)](https://stackoverflow.com/users/3692177/sebassbm) [SebasSBM](https://stackoverflow.com/users/3692177/sebassbm) 92833 gold badges99 silver badges3535 bronze badges ## Comments Add a comment This answer is useful 2 Save this answer. Show activity on this post. How about using **getModifierState()** > The getModifierState() method returns true if the specified modifier key was pressed, or activated. You can use it like: ``` Copy ``` This will simply check if CapsLock is **ON** or **OFF** and show it in console. You can change the way the function you want to work. And then use this function on **keydown** or **keyup** for example. ``` Copy<input type="text" onkeydown="checkIfCapsLockIsOn(event)"> ``` [Share](https://stackoverflow.com/a/70013486 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/70013486/edit) Follow Follow this answer to receive notifications answered Nov 18, 2021 at 1:21 [![Alireza's user avatar](https://i.sstatic.net/WtfBG.png?s=64)](https://stackoverflow.com/users/5423108/alireza) [Alireza](https://stackoverflow.com/users/5423108/alireza) 106k2727 gold badges280280 silver badges173173 bronze badges ## Comments Add a comment This answer is useful 1 Save this answer. Show activity on this post. Based on answer of @joshuahedlund since it worked fine for me. I made the code a function so it can be reused, and linked it to the body in my case. It can be linked to the password field only if you prefer. ``` Copy ``` [Share](https://stackoverflow.com/a/28543159 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/28543159/edit) Follow Follow this answer to receive notifications answered Feb 16, 2015 at 14:02 [![Cedric Simon's user avatar](https://www.gravatar.com/avatar/f2aa715dc1bb726216ce30ffc4c1c110?s=64&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/2838910/cedric-simon) [Cedric Simon](https://stackoverflow.com/users/2838910/cedric-simon) 4,66944 gold badges4343 silver badges5353 bronze badges ## Comments Add a comment This answer is useful 1 Save this answer. Show activity on this post. **React** ``` Copy ``` *** ``` Copy ``` *** ``` Copy ``` [Share](https://stackoverflow.com/a/46008107 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/46008107/edit) Follow Follow this answer to receive notifications answered Sep 1, 2017 at 21:21 [![José Araújo's user avatar](https://i.sstatic.net/DGdda.jpg?s=64)](https://stackoverflow.com/users/3845227/jos%C3%A9-ara%C3%BAjo) [José Araújo](https://stackoverflow.com/users/3845227/jos%C3%A9-ara%C3%BAjo) 6711 silver badge55 bronze badges ## Comments Add a comment This answer is useful 1 Save this answer. Show activity on this post. [Mottie's](https://stackoverflow.com/users/145346/mottie) and [Diego Vieira's](https://stackoverflow.com/users/1086469/diego-vieira) [response](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript/34277417#34277417) above is what we ended up using and should be the accepted answer now. However, before I noticed it, I wrote this little javascript function that doesn't rely on character codes... ``` Copy ``` Then call it in an event handler like so `capsLockIsOnKeyDown.capsLockIsOnKeyDown(event)` But again, we ended up just using @Mottie s and @Diego Vieira s response [Share](https://stackoverflow.com/a/49411927 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/49411927/edit) Follow Follow this answer to receive notifications answered Mar 21, 2018 at 16:37 [![Chris's user avatar](https://www.gravatar.com/avatar/dd251f9c7f5eec2131cafd90ebc11d13?s=64&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/4934902/chris) [Chris](https://stackoverflow.com/users/4934902/chris) 47544 silver badges1414 bronze badges ## Comments Add a comment This answer is useful 0 Save this answer. Show activity on this post. In this below code it will be show alert when Caps lock on and they press key using shift. if we return false; then current char will not append to text page. ``` Copy ``` [Share](https://stackoverflow.com/a/4333349 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 2.5](https://creativecommons.org/licenses/by-sa/2.5/ "The current license for this post: CC BY-SA 2.5") [Improve this answer](https://stackoverflow.com/posts/4333349/edit) Follow Follow this answer to receive notifications [edited Dec 2, 2010 at 9:48](https://stackoverflow.com/posts/4333349/revisions "show all edits to this post") [![nickf's user avatar](https://www.gravatar.com/avatar/f092dfd45793e9483281d4205b674823?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/9021/nickf) [nickf](https://stackoverflow.com/users/9021/nickf) 548k199199 gold badges660660 silver badges727727 bronze badges answered Dec 2, 2010 at 9:14 [![Naga Harish M's user avatar](https://www.gravatar.com/avatar/d83c4a03468b03dfa4198e798ca668c1?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/486119/naga-harish-m) [Naga Harish M](https://stackoverflow.com/users/486119/naga-harish-m) 2,79922 gold badges3232 silver badges4747 bronze badges ## 2 Comments Add a comment [![](https://www.gravatar.com/avatar/bb430dc40c4648586562d2ef22c8557b?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/109392/awe) awe [awe](https://stackoverflow.com/users/109392/awe) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment32766081_4333349) Only works if caps lock is on. If caps lock is off, it still reports that caps lock is on but with shift key pressed (both with shift key actually pressed or not). 2014-02-10T11:43:50.29Z+00:00 0 Reply - Copy link [![](https://www.gravatar.com/avatar/d83c4a03468b03dfa4198e798ca668c1?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/486119/naga-harish-m) Naga Harish M [Naga Harish M](https://stackoverflow.com/users/486119/naga-harish-m) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment32770716_4333349) Ok Sorry about that @awe 2014-02-10T13:38:01.07Z+00:00 0 Reply - Copy link This answer is useful 0 Save this answer. Show activity on this post. try this out simple code in easy to understand This is the Script ``` Copy ``` And the Html ``` Copy ``` [Share](https://stackoverflow.com/a/13233539 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/13233539/edit) Follow Follow this answer to receive notifications answered Nov 5, 2012 at 13:54 [![sourabh kasliwal's user avatar](https://graph.facebook.com/100000604398402/picture?type=large)](https://stackoverflow.com/users/1501138/sourabh-kasliwal) [sourabh kasliwal](https://stackoverflow.com/users/1501138/sourabh-kasliwal) 97533 gold badges88 silver badges2121 bronze badges ## Comments Add a comment This answer is useful 0 Save this answer. Show activity on this post. try to use this code. ``` Copy ``` Good Luck :) [Share](https://stackoverflow.com/a/23981757 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/23981757/edit) Follow Follow this answer to receive notifications [edited Jun 3, 2014 at 8:05](https://stackoverflow.com/posts/23981757/revisions "show all edits to this post") answered Jun 1, 2014 at 16:05 [![Oday Fraiwan's user avatar](https://www.gravatar.com/avatar/12ef1d6c67ae4510e1b5e4df4f1c78ce?s=64&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/3540036/oday-fraiwan) [Oday Fraiwan](https://stackoverflow.com/users/3540036/oday-fraiwan) 1,15711 gold badge99 silver badges2323 bronze badges ## Comments Add a comment This answer is useful 0 Save this answer. Show activity on this post. Here is a custom jquery plugin, using jquery ui, made up of all the good ideas on this page and leverages the tooltip widget. The caps lock message is auto applied all password boxes and requires no changes to your current html. Custom plug in code... ``` Copy ``` Apply to all password elements... ``` Copy ``` [Share](https://stackoverflow.com/a/34687411 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/34687411/edit) Follow Follow this answer to receive notifications answered Jan 8, 2016 at 22:50 [![Ben Gripka's user avatar](https://www.gravatar.com/avatar/aa7c2a6e79d1b3151cc13be7f3e312fe?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/530658/ben-gripka) [Ben Gripka](https://stackoverflow.com/users/530658/ben-gripka) 16\.6k66 gold badges5050 silver badges4343 bronze badges ## Comments Add a comment This answer is useful 0 Save this answer. Show activity on this post. **Javascript Code** ``` Copy ``` **We now need to associate this script using Html** ``` Copy ``` [Share](https://stackoverflow.com/a/38611590 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/38611590/edit) Follow Follow this answer to receive notifications answered Jul 27, 2016 at 11:23 [![M Arfan's user avatar](https://i.sstatic.net/vTnqbS6o.png?s=64)](https://stackoverflow.com/users/1109197/m-arfan) [M Arfan](https://stackoverflow.com/users/1109197/m-arfan) 4,60477 gold badges3333 silver badges4747 bronze badges ## Comments Add a comment This answer is useful 0 Save this answer. Show activity on this post. it is late i know but, this can be helpfull someone else. so here is my simpliest solution (with Turkish chars); ``` Copy ``` [Share](https://stackoverflow.com/a/51554059 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/51554059/edit) Follow Follow this answer to receive notifications answered Jul 27, 2018 at 8:36 [![nadir's user avatar](https://graph.facebook.com/613184130/picture?type=large)](https://stackoverflow.com/users/3248989/nadir) [nadir](https://stackoverflow.com/users/3248989/nadir) 6311 silver badge1111 bronze badges ## Comments Add a comment This answer is useful 0 Save this answer. Show activity on this post. So I found this page and didn't really like the solutions I found so I figured one out and am offering it up to all of you. For me, it only matters if the caps lock is on if I'm typing letters. This code solved the problem for me. Its quick and easy and gives you a capsIsOn variable to reference whenever you need it. ``` Copy ``` Run code snippet Edit code snippet Hide Results Copy to answer Expand [Share](https://stackoverflow.com/a/52765144 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/52765144/edit) Follow Follow this answer to receive notifications answered Oct 11, 2018 at 16:44 [![Mike Sraj's user avatar](https://www.gravatar.com/avatar/3afba5b364bfec32e06a6750b9a994c2?s=64&d=identicon&r=PG&f=y&so-version=2)](https://stackoverflow.com/users/9576898/mike-sraj) [Mike Sraj](https://stackoverflow.com/users/9576898/mike-sraj) 8111 silver badge44 bronze badges ## Comments Add a comment This answer is useful 0 Save this answer. Show activity on this post. The CapsLock observing code can be wrapped in a react hook to be easily integrated with react component code. ``` Copy ``` usage ``` Copy ``` [Share](https://stackoverflow.com/a/79562487 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/ "The current license for this post: CC BY-SA 4.0") [Improve this answer](https://stackoverflow.com/posts/79562487/edit) Follow Follow this answer to receive notifications [edited Dec 18, 2025 at 15:24](https://stackoverflow.com/posts/79562487/revisions "show all edits to this post") answered Apr 8, 2025 at 15:34 [![Martin's user avatar](https://www.gravatar.com/avatar/6a07c90d128f0a37ca0edb16637029d4?s=64&d=identicon&r=PG)](https://stackoverflow.com/users/1280867/martin) [Martin](https://stackoverflow.com/users/1280867/martin) 6,28822 gold badges2828 silver badges4949 bronze badges ## Comments Add a comment This answer is useful \-1 Save this answer. Show activity on this post. When you type, if caplock is on, it could automatically convert the current char to lowercase. That way even if caplocks is on, it will not behave like it is on the current page. To inform your users you could display a text saying that caplocks is on, but that the form entries are converted. [Share](https://stackoverflow.com/a/8555374 "Short permalink to this answer") Share a link to this answer Copy link [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/ "The current license for this post: CC BY-SA 3.0") [Improve this answer](https://stackoverflow.com/posts/8555374/edit) Follow Follow this answer to receive notifications answered Dec 18, 2011 at 22:33 [![Frederik.L's user avatar](https://i.sstatic.net/SJtHC.png?s=64)](https://stackoverflow.com/users/980869/frederik-l) [Frederik.L](https://stackoverflow.com/users/980869/frederik-l) 5,62022 gold badges3333 silver badges4141 bronze badges ## 2 Comments Add a comment [![](https://www.gravatar.com/avatar/eab4d50f6daf590222568f28a96b47a1?s=48&d=identicon&r=PG)](https://stackoverflow.com/users/706499/dave-liepmann) Dave Liepmann [Dave Liepmann](https://stackoverflow.com/users/706499/dave-liepmann) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment13172354_8555374) Yes, but then you'd still need to detect caps lock. Plus, this means that you're disallowing uppercases in passwords, which is sub-optimal. 2012-04-20T14:49:47.643Z+00:00 0 Reply - Copy link [![](https://i.sstatic.net/SJtHC.png?s=64)](https://stackoverflow.com/users/980869/frederik-l) Frederik.L [Frederik.L](https://stackoverflow.com/users/980869/frederik-l) [Over a year ago](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript#comment17665644_8555374) to detect if caps lock is on, you have to check if the lowercase version of the char you sent is different from it, if it is --\> caps lock, then «Warning : you are using caps lock but our system is converting in lower case», I guess javascript isn't meant to detect caps lock after all (checkings caps lock need a system access), you must find the way around that best fits your need 2012-10-22T17:53:33.91Z+00:00 0 Reply - Copy link 1 [2](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript?page=2&tab=scoredesc#tab-top "Go to page 2") [Next](https://stackoverflow.com/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript?page=2&tab=scoredesc#tab-top "Go to page 2") **[Protected question](https://stackoverflow.com/help/privileges/protect-questions)**. To answer this question, you need to have at least 10 reputation on this site (not counting the [association bonus](https://meta.stackexchange.com/questions/141648/what-is-the-association-bonus-and-how-does-it-work)). The reputation requirement helps protect this question from spam and non-answer activity. Start asking to get answers Find the answer to your question by asking. [Ask question](https://stackoverflow.com/questions/ask) Explore related questions - [javascript](https://stackoverflow.com/questions/tagged/javascript "show questions tagged 'javascript'") - [keyboard](https://stackoverflow.com/questions/tagged/keyboard "show questions tagged 'keyboard'") - [capslock](https://stackoverflow.com/questions/tagged/capslock "show questions tagged 'capslock'") See similar questions with these tags. - The Overflow Blog - [Are you learning with AI? We want to know about it\!](https://stackoverflow.blog/2026/01/29/are-you-learning-with-ai-we-want-to-know-about-it/?cb=1) - [Wanna see a CSS magic trick?](https://stackoverflow.blog/2026/01/30/wanna-see-a-css-magic-trick/?cb=1) - Featured on Meta - [Results of the January 2026 Community Asks Sprint: Community Badges](https://meta.stackexchange.com/questions/417043/results-of-the-january-2026-community-asks-sprint-community-badges?cb=1) - [All users on Stack Exchange can now participate in chat](https://meta.stackexchange.com/questions/417109/all-users-on-stack-exchange-can-now-participate-in-chat?cb=1) - [Policy: Generative AI (e.g., ChatGPT) is banned](https://meta.stackoverflow.com/questions/421831/policy-generative-ai-e-g-chatgpt-is-banned?cb=1) - [Stack Overflow now uses machine learning to flag spam automatically](https://meta.stackoverflow.com/questions/437959/stack-overflow-now-uses-machine-learning-to-flag-spam-automatically?cb=1) - [No, I do not believe this is the end](https://meta.stackoverflow.com/questions/438009/no-i-do-not-believe-this-is-the-end?cb=1) [Visit chat](https://chat.stackoverflow.com/) Community activity Last 1 hr - Users online activity 6015 users online - 8 questions - 12 answers - 18 comments - 120 upvotes Popular tags [android](https://stackoverflow.com/questions/tagged/android)[reporting-services](https://stackoverflow.com/questions/tagged/reporting-services)[java](https://stackoverflow.com/questions/tagged/java)[c\#](https://stackoverflow.com/questions/tagged/c)[python](https://stackoverflow.com/questions/tagged/python) Popular unanswered question [Getting android.util.Log to show stacktrace of UnknownHostException](https://stackoverflow.com/questions/40736584) [android](https://stackoverflow.com/questions/tagged/android)[exception](https://stackoverflow.com/questions/tagged/exception)[logging](https://stackoverflow.com/questions/tagged/logging)[unknown-host](https://stackoverflow.com/questions/tagged/unknown-host) [![User avatar](https://www.gravatar.com/avatar/b6e4cbfb6e9473115421f6e480c6d790?s=256&d=identicon&r=PG)](https://stackoverflow.com/users/210368) [fgysin](https://stackoverflow.com/users/210368) - 12k 3,357 days ago #### Linked [25](https://stackoverflow.com/questions/2308895/detect-caps-lock-on-off-using-jquery?lq=1 "Question score (upvotes - downvotes)") [Detect caps lock on/off using jQuery](https://stackoverflow.com/questions/2308895/detect-caps-lock-on-off-using-jquery?noredirect=1&lq=1) [10](https://stackoverflow.com/questions/4810454/how-do-i-detect-the-caps-lock-state-in-a-password-field?lq=1 "Question score (upvotes - downvotes)") [How do I detect the CAPS LOCK state in a password field](https://stackoverflow.com/questions/4810454/how-do-i-detect-the-caps-lock-state-in-a-password-field?noredirect=1&lq=1) [2](https://stackoverflow.com/questions/24029996/jquery-not-able-to-detect-the-caps-lock-on-and-off-and-keypress-are-capital-or-s?lq=1 "Question score (upvotes - downvotes)") [jquery not able to detect the caps lock on and off and keypress are capital or small](https://stackoverflow.com/questions/24029996/jquery-not-able-to-detect-the-caps-lock-on-and-off-and-keypress-are-capital-or-s?noredirect=1&lq=1) [0](https://stackoverflow.com/questions/16007691/show-caps-lock-is-on-using-jquery?lq=1 "Question score (upvotes - downvotes)") [show caps lock is on using jQuery](https://stackoverflow.com/questions/16007691/show-caps-lock-is-on-using-jquery?noredirect=1&lq=1) [0](https://stackoverflow.com/questions/21819814/is-there-a-way-to-know-if-caps-lock-is-pressed-in-a-web-page?lq=1 "Question score (upvotes - downvotes)") [is there a way to know if CAPS LOCK is pressed in a web page?](https://stackoverflow.com/questions/21819814/is-there-a-way-to-know-if-caps-lock-is-pressed-in-a-web-page?noredirect=1&lq=1) [0](https://stackoverflow.com/questions/21243637/detect-capslock-press-on-a-webpage?lq=1 "Question score (upvotes - downvotes)") [Detect CapsLock Press on a webPage](https://stackoverflow.com/questions/21243637/detect-capslock-press-on-a-webpage?noredirect=1&lq=1) [22](https://stackoverflow.com/questions/14943966/javascript-string-fromcharcode-case-sensitivity?lq=1 "Question score (upvotes - downvotes)") [Javascript String.fromCharCode Case Sensitivity?](https://stackoverflow.com/questions/14943966/javascript-string-fromcharcode-case-sensitivity?noredirect=1&lq=1) [20](https://stackoverflow.com/questions/7029152/is-there-a-way-how-to-detect-ie10s-caps-lock-is-on-feature?lq=1 "Question score (upvotes - downvotes)") [Is there a way how to detect IE10's "Caps Lock is on" feature?](https://stackoverflow.com/questions/7029152/is-there-a-way-how-to-detect-ie10s-caps-lock-is-on-feature?noredirect=1&lq=1) [6](https://stackoverflow.com/questions/45035330/detect-and-warn-users-about-caps-lock-is-on?lq=1 "Question score (upvotes - downvotes)") [Detect and warn users about caps lock is on](https://stackoverflow.com/questions/45035330/detect-and-warn-users-about-caps-lock-is-on?noredirect=1&lq=1) [7](https://stackoverflow.com/questions/5371732/detect-caps-lock-status-on-page-load-or-similar?lq=1 "Question score (upvotes - downvotes)") [detect caps lock status on page load (or similar)](https://stackoverflow.com/questions/5371732/detect-caps-lock-status-on-page-load-or-similar?noredirect=1&lq=1) [See more linked questions](https://stackoverflow.com/questions/linked/348792?lq=1) #### Related [0](https://stackoverflow.com/questions/1388879/detecting-key-capslock-in-a-textbox?rq=3 "Question score (upvotes - downvotes)") [detecting key (capslock) in a textbox](https://stackoverflow.com/questions/1388879/detecting-key-capslock-in-a-textbox?rq=3) [7](https://stackoverflow.com/questions/5371732/detect-caps-lock-status-on-page-load-or-similar?rq=3 "Question score (upvotes - downvotes)") [detect caps lock status on page load (or similar)](https://stackoverflow.com/questions/5371732/detect-caps-lock-status-on-page-load-or-similar?rq=3) [0](https://stackoverflow.com/questions/7903368/how-to-detect-caps-lock-in-javascript-without-comparing-what-was-typed-with-if-s?rq=3 "Question score (upvotes - downvotes)") [How to detect caps lock in javascript without comparing what was typed with if shift pressed?](https://stackoverflow.com/questions/7903368/how-to-detect-caps-lock-in-javascript-without-comparing-what-was-typed-with-if-s?rq=3) [0](https://stackoverflow.com/questions/10185366/check-capslock-is-on-or-off-on-button-click?rq=3 "Question score (upvotes - downvotes)") [Check capslock is on or off on button click](https://stackoverflow.com/questions/10185366/check-capslock-is-on-or-off-on-button-click?rq=3) [0](https://stackoverflow.com/questions/10534664/how-do-i-turn-on-off-the-caps-lock-key?rq=3 "Question score (upvotes - downvotes)") [How do i Turn ON/OFF the Caps lock key](https://stackoverflow.com/questions/10534664/how-do-i-turn-on-off-the-caps-lock-key?rq=3) [7](https://stackoverflow.com/questions/10680935/how-can-i-check-if-capslock-is-on-without-waiting-for-the-user-to-type-character?rq=3 "Question score (upvotes - downvotes)") [How can I check if capslock is on without waiting for the user to type character using JavaScript?](https://stackoverflow.com/questions/10680935/how-can-i-check-if-capslock-is-on-without-waiting-for-the-user-to-type-character?rq=3) [1](https://stackoverflow.com/questions/11392470/detect-if-capslock-is-down?rq=3 "Question score (upvotes - downvotes)") [Detect if capslock is down](https://stackoverflow.com/questions/11392470/detect-if-capslock-is-down?rq=3) [3](https://stackoverflow.com/questions/11881359/check-for-capslock-on-in-onfocus-event?rq=3 "Question score (upvotes - downvotes)") [Check for CapsLock ON in "onfocus" event](https://stackoverflow.com/questions/11881359/check-for-capslock-on-in-onfocus-event?rq=3) [3](https://stackoverflow.com/questions/30746616/detecting-when-caps-lock-is-on?rq=3 "Question score (upvotes - downvotes)") [Detecting when CAPS LOCK is ON](https://stackoverflow.com/questions/30746616/detecting-when-caps-lock-is-on?rq=3) [6](https://stackoverflow.com/questions/40136839/how-can-i-detect-if-caps-lock-status-is-active-without-press-any-key-using-js?rq=3 "Question score (upvotes - downvotes)") [How can I detect if CAPS LOCK STATUS is active without press any key using JS?](https://stackoverflow.com/questions/40136839/how-can-i-detect-if-caps-lock-status-is-active-without-press-any-key-using-js?rq=3) #### [Hot Network Questions](https://stackexchange.com/questions?tab=hot) - [Does this practice of omitting an initial quotation mark have precedent?](https://literature.stackexchange.com/questions/31467/does-this-practice-of-omitting-an-initial-quotation-mark-have-precedent) - [What's the official site for Vietnam e-Visa applications](https://travel.stackexchange.com/questions/203175/whats-the-official-site-for-vietnam-e-visa-applications) - [Are there any tips/tricks to improve simplification of this flavor of expression in Wolfram Engine?](https://mathematica.stackexchange.com/questions/318565/are-there-any-tips-tricks-to-improve-simplification-of-this-flavor-of-expression) - [Remove unconnected points in Geometry Nodes](https://blender.stackexchange.com/questions/344832/remove-unconnected-points-in-geometry-nodes) - [Bounding indexes of normal cores, when there is extra information](https://math.stackexchange.com/questions/5122285/bounding-indexes-of-normal-cores-when-there-is-extra-information) - [Calculate values ​of standard normal distribution table as macro](https://tex.stackexchange.com/questions/758979/calculate-values-of-standard-normal-distribution-table-as-macro) - [Time period of a pendulum filled with water](https://physics.stackexchange.com/questions/868498/time-period-of-a-pendulum-filled-with-water) - [Does the castle doctrine/stand-your-ground apply when the assailant is outside but attacking the home itself?](https://law.stackexchange.com/questions/114076/does-the-castle-doctrine-stand-your-ground-apply-when-the-assailant-is-outside-b) - [Changing from B1/B2 visa](https://travel.stackexchange.com/questions/203169/changing-from-b1-b2-visa) - [Please check the construction of the measure in MuseScore](https://music.stackexchange.com/questions/143145/please-check-the-construction-of-the-measure-in-musescore) - [(Romans 10:6-8) The righteousness which is of faith speaketh?](https://hermeneutics.stackexchange.com/questions/114346/romans-106-8-the-righteousness-which-is-of-faith-speaketh) - [What can an infringed party do when a publisher ignores DMCA takedown notices?](https://law.stackexchange.com/questions/114057/what-can-an-infringed-party-do-when-a-publisher-ignores-dmca-takedown-notices) - [What is the meaning of this road sign?](https://history.stackexchange.com/questions/79811/what-is-the-meaning-of-this-road-sign) - [Is it a good idea to connect LEDs in parallel instead of series (string configuration) to TPS92511 work with lower values of voltages like Vin = 5V?](https://electronics.stackexchange.com/questions/765077/is-it-a-good-idea-to-connect-leds-in-parallel-instead-of-series-string-configur) - [What does Jtemal mean?](https://german.stackexchange.com/questions/82087/what-does-jtemal-mean) - [How is numerical precision/accuracy determined when converting RA/Dec in sexagesimal format to decimal degrees for angular separation calculations?](https://astronomy.stackexchange.com/questions/62154/how-is-numerical-precision-accuracy-determined-when-converting-ra-dec-in-sexages) - [How can the Etherealness spell be used effectively in a party-based game?](https://rpg.stackexchange.com/questions/218656/how-can-the-etherealness-spell-be-used-effectively-in-a-party-based-game) - [How common is it for China's military top brass to publicly dilute the political leadership's objectives?](https://politics.stackexchange.com/questions/94169/how-common-is-it-for-chinas-military-top-brass-to-publicly-dilute-the-political) - [Can we make SOS decompositions strictly feasible with a suitable denominator?](https://mathoverflow.net/questions/507624/can-we-make-sos-decompositions-strictly-feasible-with-a-suitable-denominator) - [ParametricPlot: highlight independent parameter along curve](https://mathematica.stackexchange.com/questions/318586/parametricplot-highlight-independent-parameter-along-curve) - [Macro with mandatory argument in xint (xintexpr)](https://tex.stackexchange.com/questions/758988/macro-with-mandatory-argument-in-xint-xintexpr) - [Is This Video on Bell's Theorem Wrong?](https://physics.stackexchange.com/questions/868447/is-this-video-on-bells-theorem-wrong) - [Why does Susan Sto Helit get involved in The Hogfather?](https://scifi.stackexchange.com/questions/303071/why-does-susan-sto-helit-get-involved-in-the-hogfather) - [How to tackle the feelings of being overwhelmed in a tenure-track position?](https://academia.stackexchange.com/questions/225786/how-to-tackle-the-feelings-of-being-overwhelmed-in-a-tenure-track-position) [Question feed](https://stackoverflow.com/feeds/question/348792 "Feed of this question and its answers") # Subscribe to RSS Question feed To subscribe to this RSS feed, copy and paste this URL into your RSS reader. ![](https://stackoverflow.com/posts/348792/ivc/7fd4?prg=09f5bbbb-7858-4642-926c-7cf4b6889532) lang-js # Why are you flagging this comment? Probable spam. This comment promotes a product, service or website while [failing to disclose the author's affiliation](https://stackoverflow.com/help/promotion). Unfriendly or contains harassment/bigotry/abuse. This comment is unkind, insulting or attacks another person or group. Learn more in our [Abusive behavior policy](https://stackoverflow.com/conduct/abusive-behavior). Not needed. This comment is not relevant to the post. ``` ``` Enter at least 6 characters Something else. A problem not listed above. Try to be as specific as possible. ``` ``` Enter at least 6 characters Flag comment Cancel You have 0 flags left today # ![Illustration of upvote icon after it is clicked](https://stackoverflow.com/Content/Img/modal/img-upvote.png?v=fce73bd9724d) # Hang on, you can't upvote just yet. You'll need to complete a few actions and gain 15 reputation points before being able to upvote. **Upvoting** indicates when questions and answers are useful. [What's reputation and how do I get it?](https://stackoverflow.com/help/whats-reputation) Instead, you can save this post to reference later. Save this post for later Not now ##### [Stack Overflow](https://stackoverflow.com/) - [Questions](https://stackoverflow.com/questions) - [Help](https://stackoverflow.com/help) - [Chat](https://chat.stackoverflow.com/?tab=explore) ##### [Business](https://stackoverflow.co/) - [Stack Internal](https://stackoverflow.co/internal/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=footer&utm_content=teams) - [Stack Data Licensing](https://stackoverflow.co/data-licensing/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=footer&utm_content=data-licensing) - [Stack Ads](https://stackoverflow.co/advertising/?utm_medium=referral&utm_source=stackoverflow-community&utm_campaign=footer&utm_content=advertising) ##### [Company](https://stackoverflow.co/) - [About](https://stackoverflow.co/) - [Press](https://stackoverflow.co/company/press/) - [Work Here](https://stackoverflow.co/company/work-here/) - [Legal](https://stackoverflow.com/legal) - [Privacy Policy](https://stackoverflow.com/legal/privacy-policy) - [Terms of Service](https://stackoverflow.com/legal/terms-of-service/public) - [Contact Us](https://stackoverflow.com/contact) - Cookie Settings - [Cookie Policy](https://policies.stackoverflow.co/stack-overflow/cookie-policy) ##### [Stack Exchange Network](https://stackexchange.com/) - [Technology](https://stackexchange.com/sites#technology) - [Culture & recreation](https://stackexchange.com/sites#culturerecreation) - [Life & arts](https://stackexchange.com/sites#lifearts) - [Science](https://stackexchange.com/sites#science) - [Professional](https://stackexchange.com/sites#professional) - [Business](https://stackexchange.com/sites#business) - [API](https://api.stackexchange.com/) - [Data](https://data.stackexchange.com/) - [Blog](https://stackoverflow.blog/?blb=1) - [Facebook](https://www.facebook.com/officialstackoverflow/) - [Twitter](https://twitter.com/stackoverflow) - [LinkedIn](https://linkedin.com/company/stack-overflow) - [Instagram](https://www.instagram.com/thestackoverflow) Site design / logo © 2026 Stack Exchange Inc; user contributions licensed under [CC BY-SA](https://stackoverflow.com/help/licensing) . rev 2026.1.29.39263
Readable Markdown
Yet another version, clear and simple, handles shifted capsLock, and not constrained to ascii I think: ``` document.onkeypress = function (e) { e = e || window.event; if (e.charCode === 0 || e.ctrlKey || document.onkeypress.punctuation.indexOf(e.charCode) >= 0) return; var s = String.fromCharCode(e.charCode); // or e.keyCode for compatibility, but then have to handle MORE non-character keys var s2 = e.shiftKey ? s.toUpperCase() : s.toLowerCase(); var capsLockOn = (s2 !== s); document.getElementById('capslockWarning').style.display = capsLockOn ? '' : 'none'; } document.onkeypress.punctuation = [33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,91,92,93,94,95,96,123,124,125,126]; ``` **Edit:** Sense of capsLockOn was reversed, doh, fixed. **Edit \#2:** After checking this out some more, I've made a few changes, a bit more detailed code unfortunately, but it handles more actions appropriately. - Using e.charCode instead of e.keyCode and checking for 0 values skips a lot of non-character keypresses, without coding anything specific to a given language or charset. From my understanding, it's slightly less compatible, so older, non-mainstream, or mobile browsers may not behave as this code expects, but it's worth it, for my situation anyway. - Checking against a list of known punctuation codes prevents them from being seen as false negatives, since they're not affected by caps lock. Without this, the caps lock indicator gets hidden when you type any of those punctuation characters. By specifying an excluded set, rather than an included one, it should be more compatible with extended characters. This is the ugliest, special-casiest bit, and there's some chance that non-Western languages have different enough punctuation and/or punctuation codes to be a problem, but again it's worth it IMO, at least for my situation.
Shard169 (laksa)
Root Hash714406497480128969
Unparsed URLcom,stackoverflow!/questions/348792/how-do-you-tell-if-caps-lock-is-on-using-javascript s443