MCQ Quiz game source code in HTML, CSS and JavaScript

Add responsive MCQ quiz to your website using HTML, CSS, JavaScript. No plugin or backend needed.
MCQ Quiz Code in HTML CSS JavaScript

Hello friends, wellcome to edusynth.in — If you’re planning to add an interactive quiz to your website, this simple MCQ system can help you do that quickly. It’s built using HTML, CSS, and JavaScript, and works smoothly on both desktop and mobile.

Table of Contents

What Is This Quiz Tool?

This is a lightweight MCQ quiz tool that lets users answer multiple-choice questions. When someone selects an option, they get instant feedback. Correct answers turn green with a success sound, and incorrect ones turn red with a buzzer.

It also shows a final score and certificate-like message. It’s a perfect fit if you want to add a quiz to your blog or educational site.

Why Use an Interactive Quiz?

Interactive content keeps users engaged. A simple MCQ system for websites like this makes your content more useful, especially for learning-based platforms. Visitors don’t just read — they participate.

Using this kind of responsive quiz system can increase user time on page and improve SEO indirectly through better engagement.

Where Can You Use It?

You can use this quiz on:

  1. Blogger posts using HTML/JavaScript
  2. WordPress with HTML blocks
  3. Educational platforms or test-prep sites
  4. Skill check pages or general knowledge quizzes

It’s ideal if you’re looking to add a quiz feature to a website without any plugin.

Mobile and Desktop Friendly

This is a responsive online quiz tool. It adjusts automatically to different screen sizes. On mobile, the buttons are easy to tap. On desktop, the layout looks clean and centered.

All interactive effects like sound and feedback work the same across devices.

What Makes It Special?

This quiz doesn’t require any backend or database. It runs fully in the browser. That’s why it’s called a lightweight HTML CSS JS quiz script. No installation, no login — just copy and paste.

Also, it supports sound effects and shows a scorecard at the end, which makes it more engaging than plain text quizzes.

How to Use It on Your Website

To add this quiz, you’ll need to insert three types of code in your site:

1. HTML Code



<div id="quizContainer">
    <fieldset>
        <h3>1 ➤ This is question no 1</h3>
        <input type="radio" name="q1" id="q1-a1" value="0">
        <label for="q1-a1" class="answerOption">Answer 1</label>

        <input type="radio" name="q1" id="q1-a2" value="1" class="correct">
        <label for="q1-a2" class="answerOption">Answer 2</label>

        <input type="radio" name="q1" id="q1-a3" value="0">
        <label for="q1-a3" class="answerOption">Answer 3</label>

        <input type="radio" name="q1" id="q1-a4" value="0">
        <label for="q1-a4" class="answerOption">Answer 4</label>
    </fieldset>

    <fieldset>
        <h3>2 ➤ This is question no 2</h3>
        <input type="radio" name="q2" id="q2-a1" value="0">
        <label for="q2-a1" class="answerOption">Answer 1</label>

        <input type="radio" name="q2" id="q2-a2" value="0">
        <label for="q2-a2" class="answerOption">Answer 2</label>

        <input type="radio" name="q2" id="q2-a3" value="0">
        <label for="q2-a3" class="answerOption">Answer 3</label>

        <input type="radio" name="q2" id="q2-a4" value="1" class="correct">
        <label for="q2-a4" class="answerOption">Answer 4</label>
    </fieldset>

    <button type="button" id="submitQuiz" class="quiz-btn">Submit</button>
</div>

<div class="certificateContainer" id="certificateContainer">
    <h2>EduSynth</h2>
    <p id="certificateMessage">Your Score: <span id="score">0</span> / 2</p>
    <p class="certificate-text"></p>
</div>

<audio id="correct-sound" src="https://github.com/Greatidea11/Audio_edu/raw/refs/heads/main/correct-choice-43861.mp3"></audio>
<audio id="wrong-sound" src="https://github.com/edusyn1/my-js-files/raw/refs/heads/main/Wrong-buzzer.mp3"></audio>
<audio id="score-sound" src="https://github.com/edusyn1/my-js-files/raw/refs/heads/main/success-340660.mp3"></audio>

To customize your quiz, simply edit the <h3> tag to change the question text. Replace each <label> with your own answer options, and set the correct one by adding class="correct" to the correct input. Make sure the value is 1 for the right answer and 0 for others.

2. CSS Code



#quizContainer{max-width:500px;margin:auto;padding:15px;background:white;border-radius:10px;box-shadow:0px 0px 10px rgba(0,0,0,0.2)}
fieldset{border:1px solid #000;border-radius:5px;padding:10px;background:#e9edf5;margin-bottom:15px}
h3{margin:0 0 10px;font-size:16px}
.answerOption{display:block;width:100%;padding:10px;margin:5px 0;border:1px solid blue;background:#ccc;border-radius:5px;cursor:pointer}
input[type="radio"]{display:none}
input[type="radio"]:checked + .answerOption{background:red;color:white}
input[type="radio"]:checked.correct + .answerOption{background:green}
.quiz-btn{background:linear-gradient(45deg,red,blue);color:white;padding:10px;border:none;width:100%;border-radius:5px;cursor:pointer;font-size:16px}
.certificateContainer{display:none;width:90%;max-width:600px;margin:20px auto;padding:20px;background:#fff5cc;border:10px solid #d4af37;border-radius:10px;box-shadow:0 0 15px rgba(0,0,0,0.3);text-align:center}
.certificateContainer h2{font-size:24px;color:#d4af37;margin-bottom:10px}
.certificateContainer p{font-size:18px;margin:5px 0}
.certificate-text{font-style:italic;font-weight:bold;margin-top:10px}

You don’t need to make any changes to the CSS. It is already optimized for both mobile and desktop layout. Just copy and paste it as provided.

3. JavaScript Code



document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll('input[type="radio"]').forEach(r=>{r.addEventListener('change',function(){this.classList.contains("correct")?document.getElementById("correct-sound").play():document.getElementById("wrong-sound").play();document.querySelectorAll(`input[name="${this.name}"]`).forEach(x=>x.disabled=true);});});document.getElementById("submitQuiz").addEventListener("click",function(){let t=document.querySelectorAll('input[type="radio"]').length/4,s=document.querySelectorAll('input[type="radio"]:checked.correct').length;document.getElementById("score").textContent=s;document.querySelector(".certificate-text").textContent=s>=t/2?"Congratulations on your performance!":"Keep learning and improving!";document.getElementById("certificateContainer").style.display="block";document.getElementById("score-sound").play();this.disabled=true;});});

You don’t need to edit the JavaScript unless you want to change sounds or certificate text. The script automatically checks answers, shows feedback, and displays the score. Just keep the class names and values as instructed for it to work correctly.

You can use it on any webpage where custom code is allowed. It works well with Blogger, since it’s fully based on client-side code.

Add more mcq question

If you want to add more MCQ questions to your quiz, simply copy the entire <fieldset> block and update the name and id values (like q2, q3, etc.) to keep each question unique. Paste this block inside the <form> section of your HTML where the other questions are added.

<fieldset>
  <h3>2 ➤ This is question no 2</h3>
  <input type="radio" name="q2" id="q2-a1" value="0">
  <label for="q2-a1" class="answerOption">Answer 1</label>

  <input type="radio" name="q2" id="q2-a2" value="0">
  <label for="q2-a2" class="answerOption">Answer 2</label>

  <input type="radio" name="q2" id="q2-a3" value="1" class="correct">
  <label for="q2-a3" class="answerOption">Answer 3</label>

  <input type="radio" name="q2" id="q2-a4" value="0">
  <label for="q2-a4" class="answerOption">Answer 4</label>
</fieldset>

Customize Your Questions

You can change questions, answers, and even how the quiz looks. If you want to add more questions or change the certificate message, just edit the HTML and JavaScript parts. This makes it a flexible tool for any custom quiz requirement.

You can even replace sound URLs with your own hosted MP3 files if needed.

Download and Demo MCQ Quiz Tool

If you want to see the demo first, you can click the Demo button below. And if you want to get the entire code in one file, you can click the Download button to download it.

Demo

Note:This content has been created with the help of AI to ensure clarity, readability, and completeness. All information has been reviewed and customized to serve human readers.

What is an MCQ Quiz Code for websites?

It is a ready-made HTML, CSS, and JavaScript code that lets you add interactive quizzes to any webpage.

Can I use this MCQ quiz on Blogger or WordPress?

Yes, the quiz code is fully compatible with Blogger and WordPress using HTML/JS blocks.

Do I need a plugin or database for this quiz to work?

No plugin or backend is needed. The quiz works entirely on the frontend using pure HTML, CSS, and JavaScript.

Related Posts

Conclusion

This simple yet powerful interactive MCQ quiz for websites can make your content more engaging and helpful. It’s easy to set up, mobile-friendly, and doesn’t rely on heavy plugins.

If you're looking to improve user experience and add some learning-based tools to your content, this JavaScript quiz system is a great choice.

About the author

Aaqib Amin
EduSynth.in offers free apps, study materials, software, games, and helpful articles—all in one place to support your learning.

Post a Comment