Sure! Here's a simple, clean, dark-mode typing speed game all bundled into a single HTML file. It shows a random sentence to type, measures your typing speed (WPM), accuracy, and time taken. The UI is minimal and dark-themed.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Typing Speed Game</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono&display=swap');
* {
box-sizing: border-box;
}
body {
margin: 0;
background: #121212;
color: #eee;
font-family: 'JetBrains Mono', monospace;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
min-height: 100vh;
padding: 2rem 1rem;
}
h1 {
margin-bottom: 0.5rem;
font-weight: 700;
}
#sentence {
background: #1e1e1e;
border-radius: 8px;
padding: 1rem 1.5rem;
font-size: 1.25rem;
max-width: 700px;
margin-bottom: 1.5rem;
user-select: none;
line-height: 1.5;
}
#inputArea {
width: 100%;
max-width: 700px;
font-size: 1.25rem;
padding: 0.75rem 1rem;
border-radius: 8px;
border: none;
outline: none;
background: #222;
color: #eee;
font-family: 'JetBrains Mono', monospace;
box-shadow: 0 0 8px #333 inset;
}
#inputArea:disabled {
background: #333;
color: #777;
}
#stats {
margin-top: 1.5rem;
display: flex;
gap: 2rem;
font-size: 1.1rem;
max-width: 700px;
justify-content: center;
}
#stats div {
background: #1e1e1e;
padding: 0.75rem 1.25rem;
border-radius: 8px;
min-width: 120px;
text-align: center;
}
button {
margin-top: 2rem;
background: #3a86ff;
border: none;
padding: 0.75rem 2rem;
border-radius: 8px;
color: white;
font-weight: 600;
font-size: 1.1rem;
cursor: pointer;
transition: background 0.3s ease;
}
button:hover {
background: #265ecf;
}
#message {
margin-top: 1rem;
font-size: 1rem;
color: #4caf50;
min-height: 1.2em;
}
mark.correct {
background-color: #4caf50;
color: #121212;
}
mark.incorrect {
background-color: #e53935;
color: #121212;
}
</style>
</head>
<body>
<h1>Typing Speed Game</h1>
<div id="sentence"></div>
<input type="text" id="inputArea" placeholder="Start typing here..." autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />
<div id="stats">
<div>Time: <span id="time">0.0</span>s</div>
<div>WPM: <span id="wpm">0</span></div>
<div>Accuracy: <span id="accuracy">100</span>%</div>
</div>
<button id="restartBtn">Restart</button>
<div id="message"></div>
<script>
(() => {
const sentences = [
"The quick brown fox jumps over the lazy dog.",
"Typing speed games are fun and challenging.",
"Practice makes perfect, so keep typing!",
"JavaScript powers interactive web pages.",
"Dark mode is easier on the eyes at night.",
"Clean UI improves user experience significantly.",
"Consistency is key to improving typing skills.",
"Accuracy matters more than speed sometimes.",
"Focus on the text and avoid distractions.",
"Every keystroke counts in this typing game."
];
const sentenceEl = document.getElementById('sentence');
const inputArea = document.getElementById('inputArea');
const timeEl = document.getElementById('time');
const wpmEl = document.getElementById('wpm');
const accuracyEl = document.getElementById('accuracy');
const restartBtn = document.getElementById('restartBtn');
const messageEl = document.getElementById('message');
let startTime = null;
let timerInterval = null;
let currentSentence = '';
let totalTyped = 0;
let correctTyped = 0;
let finished = false;
function pickSentence() {
return sentences[Math.floor(Math.random() * sentences.length)];
}
function renderSentence(sentence, input) {
// Highlight correct and incorrect characters
let html = '';
for (let i = 0; i < sentence.length; i++) {
const char = sentence[i];
if (input[i] == null) {
html += char;
} else if (input[i] === char) {
html += `<mark class="correct">${char}</mark>`;
} else {
html += `<mark class="incorrect">${char}</mark>`;
}
}
sentenceEl.innerHTML = html;
}
function calculateWPM(charsTyped, elapsedSeconds) {
// WPM = (chars / 5) / (minutes)
return Math.round((charsTyped / 5) / (elapsedSeconds / 60));
}
function calculateAccuracy(correct, total) {
if (total === 0) return 100;
return Math.round((correct / total) * 100);
}
function startTimer() {
startTime = Date.now();
timerInterval = setInterval(() => {
const elapsed = (Date.now() - startTime) / 1000;
timeEl.textContent = elapsed.toFixed(1);
const wpm = calculateWPM(correctTyped, elapsed);
wpmEl.textContent = wpm > 0 ? wpm : 0;
}, 100);
}
function stopTimer() {
clearInterval(timerInterval);
}
function reset() {
finished = false;
currentSentence = pickSentence();
inputArea.value = '';
inputArea.disabled = false;
inputArea.focus();
totalTyped = 0;
correctTyped = 0;
timeEl.textContent = '0.0';
wpmEl.textContent = '0';
accuracyEl.textContent = '100';
messageEl.textContent = '';
renderSentence(currentSentence, '');
if (timerInterval) clearInterval(timerInterval);
startTime = null;
}
inputArea.addEventListener('input', () => {
if (finished) return;
const input = inputArea.value;
if (!startTime) startTimer();
totalTyped = input.length;
// Count correct chars
let correctCount = 0;
for (let i = 0; i < input.length; i++) {
if (input[i] === currentSentence[i]) correctCount++;
}
correctTyped = correctCount;
renderSentence(currentSentence, input);
const accuracy = calculateAccuracy(correctTyped, totalTyped);
accuracyEl.textContent = accuracy;
if (input === currentSentence) {
finished = true;
stopTimer();
inputArea.disabled = true;
messageEl.textContent = `Well done! Your typing speed is ${wpmEl.textContent} WPM with ${accuracy}% accuracy.`;
}
});
restartBtn.addEventListener('click', reset);
reset();
})();
</script>
</body>
</html>
How it works:
- A random sentence is shown.
- You type in the input box.
- Correct characters are highlighted in green, incorrect in red.
- Time, WPM, and accuracy update live.
- When you finish typing the sentence exactly, the input disables and a message shows your final stats.
- Press "Restart" to try a new sentence.
Open this file in any modern browser and start typing! Let me know if you want it extended with more features.