An interactive, modern, and minimalist web-based typing speed test app (inspired by Monkeytype) built using Vanilla HTML5, CSS3, and JavaScript.
| Technology | Usage |
|---|---|
| HTML5 | Project structure, SVG icons, semantic tags, and keyboard focus using tabindex="0". |
| CSS3 | Dark mode styling, custom variables, smooth transition animations, blur filters, and typography with Google Fonts (Roboto & Roboto Mono). |
| JavaScript (ES6+) | Pure Vanilla JS for DOM manipulation, typing listener algorithms, live timer, dynamic WPM calculation, backspace handling, and smooth cursor movement. |
- Created a clean container layout with a header displaying the 30-second timer and a "New Game" button.
- Added a game container
#gamewithtabindex="0"so the div can receive keyboard focus and capture typing events. - Added child elements for
#words(where text is rendered),#cursor(the yellow caret indicator), and#focus-error(overlay shown when the user clicks away from the game).
- Theme Variables: Defined a dark theme palette using CSS variables (
--bgColor,--primaryColor,--textPrimary,--textSecondary). - Typography: Imported
Robotofor headers andRoboto Monofor the monospaced typing test words. - Focus Detection: Used CSS pseudo-class
#game:focusto blur text and display a "Click here to focus" message whenever the game area loses focus. - Color Feedback: Styled correct letters in white (
#fff), incorrect letters in red (#f55), and active target letter highlighting. - Smooth Caret Cursor: Styled the cursor
#cursorwith smoothtransitionontopandleftproperties so it smoothly glides across letters as you type.
- Created an array of vocabulary words.
- Implemented a
randomWord()function that picks random words from the pool. - Built a
formatWord()helper to wrap each word in a<div class="word">and each letter in a<span class="letter">. - Rendered 200 random words into the
#wordscontainer upon starting anewGame().
- Added a
keyupevent listener to#gameto capture user keystrokes in real time. - Letter Matching: Compared typed key against expected character:
- If correct ➔ Adds
.correctclass (white text). - If incorrect ➔ Adds
.incorrectclass (red text). - Handles extra characters typed past the word length.
- If correct ➔ Adds
- Space Bar Navigation: Pressing
Spacemoves to the next word. Un-typed letters in the skipped word are marked incorrect. - Backspace Support: Allowed correcting mistakes:
- Deletes extra characters if present.
- Moves cursor backwards to previous letters or even previous words.
- Clears
.corrector.incorrectstate when backspacing over letters.
- Used
getBoundingClientRect()to measure exact letter positions on the screen in real-time. - Updated
#cursorposition (topandleft) dynamically after every keystroke. - Implemented vertical line scrolling (
marginTop) whenever the cursor moves past line boundaries to keep the active line centered.
- Timer: Automatically starts a 30-second countdown on the very first keystroke.
-
WPM Calculation:
$$\text{WPM} = \left( \frac{\text{Number of Correct Words}}{\text{Elapsed Time in Minutes}} \right)$$ - Game Over: Automatically ends input after 30 seconds and displays the final WPM score on screen.
- ⏱️ 30-Second Countdown: Automated game timer triggered on first keystroke.
- 📊 Accurate WPM Calculation: Only fully and correctly typed words contribute to the score.
- 🎨 Visual Feedback: Real-time color updates for typed characters (White = Correct, Red = Incorrect).
- 🖱️ Focus Protection: Blurs text and prompts user to click to focus when clicked away.
- 🔄 Restart Game: "New Game" button to instantly reset and load fresh words.
- 📱 Smooth Cursor & Scroll: Fluid caret movement and automatic text line scrolling.
- Clone or Download this project folder to your local machine.
- Open the
index.htmlfile directly in any browser (Chrome, Firefox, Edge, Safari) by double-clicking it. - Optional: Use VS Code extension Live Server to run it on a local dev server (
http://127.0.0.1:5500). - Click inside the game area to focus and start typing!