A zero-dependency, fully client-side CAPTCHA built with plain HTML, CSS & JavaScript.
Generate a random code, type it back, get instant validation — no backend, no build step, no libraries.
- Overview
- Features
- Tech Stack
- Project Structure
- Getting Started
- Usage
- How It Works
- Validation Rules
- Troubleshooting
- Contributing
- Author
- License
CAPTCHA Generator is a lightweight, single-page web app that produces a random six-character alphanumeric code on load and verifies the user's input in real time. Everything runs in the browser — there is no server, no framework and no package manager to install. Open the file and it works.
It is ideal for learning DOM manipulation, dropping into a landing page as a bot-check demo, or as a starting point for a larger form-validation project.
- ⚡ Instant setup — open
index.html, no build or server required - 🔐 Random 6-character codes drawn from digits, uppercase and lowercase letters
- ✅ Real-time validation with clear Matched, Not-Matched and empty-input feedback
- 🔄 One-click refresh that generates a brand-new code and clears the field
- 🧮 Zero dependencies — pure HTML, CSS and vanilla JavaScript
- 📱 Responsive layout with an animated gradient background
- ♿ Read-only generator field so the challenge can't be tampered with
| Technology | Role |
|---|---|
| HTML5 | Page structure, inputs and buttons |
| CSS3 | Layout, styling and the animated gradient background |
| JavaScript (ES6+) | Code generation and validation logic |
No frameworks, no bundlers, no runtime dependencies.
captcha-generator/
├── index.html # Markup: generator field, input, Submit & Refresh buttons
├── style.css # Layout, gradient animation and component styling
├── index.js # Captcha generation + validation logic
└── README.md # This file
- Clone the repository:
git clone https://github.com/Kumar44developer/captcha-generator.git
- Open the
captcha-generatorfolder and double-clickindex.html— it runs directly in any modern browser.
If you prefer a local server (e.g. to test on a phone), run one from the project folder:
# Python
python -m http.server 8123
# or Node.js
npx serve .Then visit http://localhost:8123 in your browser.
- On load, a random six-character code appears in the top field.
- Type the code exactly as shown into the input box.
- Click Submit to validate:
- correct code → Matched 😎
- wrong code → Not-Matched 😖
- empty box → prompt to enter the text
- Click Refresh anytime to get a new code.
The character pool is 0-9, A-Z and a-z. generateCaptcha() loops six times, each iteration
picking a random character and appending it to the current code, then renders it into the read-only
field. On Submit, the entered value is compared character-for-character (case-sensitive) against
the stored code and the status heading updates. Refresh simply calls generateCaptcha() again
and clears the input.
function generateCaptcha() {
const captchaLength = 6;
captcha = "";
for (let i = 0; i < captchaLength; i++) {
const randomIndex = Math.floor(Math.random() * char.length);
captcha += char.substring(randomIndex, randomIndex + 1);
}
generator.value = captcha;
display.innerText = "Captcha Generator";
}| Input state | Result |
|---|---|
| Empty | |
| Exact match (case-sensitive) | ✅ "Matched 😎" |
| Anything else | ❌ "Not-Matched 😖" |
- The code field is blank on load — make sure
index.jsloads after the DOM (it is included at the bottom of<body>). Modern browsers run it automatically. - Emoji messages render as boxes — this is an OS font issue; the logic still works.
- Nothing happens on Submit — confirm JavaScript is enabled in the browser.
Contributions are welcome! Feel free to open an issue or submit a pull request.
- Fork the project
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Created by Kumar44developer.
Distributed under the MIT License. See LICENSE for more information.