Here's a responsive and stylish quiz website with rules and start buttons:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quiz Master</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
:root {
--primary: #6c63ff;
--secondary: #ff6584;
--dark: #2c2c54;
--light: #f5f6fa;
}
body {
background-color: var(--light);
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
min-height: 100vh;
display: flex;
flex-direction: column;
}
.quiz-container {
max-width: 800px;
margin: 0 auto;
padding: 2rem;
background: white;
border-radius: 15px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
transition: all 0.3s ease;
}
.quiz-container:hover {
transform: translateY(-5px);
box-shadow: 0 15px 35px rgba(0, 0, 0, 0.15);
}
.quiz-header {
text-align: center;
margin-bottom: 2rem;
color: var(--dark);
}
.quiz-header h1 {
font-weight: 700;
margin-bottom: 0.5rem;
font-size: 2.5rem;
}
.quiz-header p {
color: #666;
font-size: 1.1rem;
}
.btn-custom {
background: var(--primary);
color: white;
border: none;
padding: 12px 30px;
border-radius: 50px;
font-weight: 600;
letter-spacing: 0.5px;
transition: all 0.3s ease;
margin: 10px;
box-shadow: 0 5px 15px rgba(108, 99, 255, 0.2);
}
.btn-custom:hover {
background: #5a52e0;
transform: translateY(-3px);
box-shadow: 0 8px 20px rgba(108, 99, 255, 0.3);
color: white;
}
.btn-secondary-custom {
background: var(--secondary);
box-shadow: 0 5px 15px rgba(255, 101, 132, 0.2);
}
.btn-secondary-custom:hover {
background: #ff4d70;
box-shadow: 0 8px 20px rgba(255, 101, 132, 0.3);
}
.rules-container {
background: #f8f9fa;
border-radius: 10px;
padding: 20px;
margin-top: 20px;
display: none;
animation: fadeIn 0.5s ease;
}
.rules-container h3 {
color: var(--dark);
margin-bottom: 15px;
}
.rules-container ul {
padding-left: 20px;
}
.rules-container li {
margin-bottom: 10px;
color: #555;
}
.quiz-section {
display: none;
animation: fadeIn 0.5s ease;
}
.question-container {
background: white;
border-radius: 10px;
padding: 20px;
margin-bottom: 20px;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
}
.options-container .option {
background: #f8f9fa;
border: 2px solid #eee;
border-radius: 10px;
padding: 15px;
margin-bottom: 10px;
cursor: pointer;
transition: all 0.2s ease;
}
.options-container .option:hover {
background: #e9ecef;
border-color: #ddd;
}
.options-container .option.selected {
background: var(--primary);
color: white;
border-color: var(--primary);
}
.quiz-footer {
display: flex;
justify-content: space-between;
margin-top: 20px;
}
.progress-container {
margin-bottom: 20px;
}
.progress {
height: 10px;
border-radius: 5px;
}
.result-container {
text-align: center;
display: none;
animation: fadeIn 0.5s ease;
}
.result-container h2 {
margin-bottom: 20px;
color: var(--dark);
}
.score {
font-size: 3rem;
font-weight: 700;
color: var(--primary);
margin-bottom: 20px;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@media (max-width: 768px) {
.quiz-container {
padding: 1.5rem;
margin: 0 15px;
}
.quiz-header h1 {
font-size: 2rem;
}
.btn-custom {
padding: 10px 20px;
font-size: 0.9rem;
}
}
</style>
</head>
<body class="d-flex align-items-center py-4">
<div class="container">
<div class="quiz-container">
<div class="quiz-header">
<h1>Quiz Master</h1>
<p>Test your knowledge with our interactive quiz!</p>
</div>
<div class="text-center">
<button id="rulesBtn" class="btn btn-custom">View Rules</button>
<button id="startBtn" class="btn btn-custom btn-secondary-custom">Start Quiz</button>
</div>
<div id="rulesContainer" class="rules-container">
<h3>Quiz Rules</h3>
<ul>
<li>The quiz consists of 5 multiple-choice questions.</li>
<li>Each question has only one correct answer.</li>
<li>You have 60 seconds to complete the entire quiz.</li>
<li>You cannot go back to previous questions once answered.</li>
<li>Your final score will be displayed at the end of the quiz.</li>
<li>Each correct answer is worth 20 points.</li>
</ul>
</div>
<div id="quizSection" class="quiz-section">
<div class="progress-container">
<div class="d-flex justify-content-between mb-1">
<span>Question <span id="currentQuestion">1</span>/5</span>
<span id="timer">60s</span>
</div>
<div class="progress">
<div id="progressBar" class="progress-bar bg-primary" role="progressbar" style="width: 0%"></div>
</div>
</div>
<div class="question-container">
<h4 id="questionText">Question text will appear here</h4>
</div>
<div id="optionsContainer" class="options-container">
<!-- Options will be added here dynamically -->
</div>
<div class="quiz-footer">
<button id="nextBtn" class="btn btn-custom">Next Question</button>
</div>
</div>
<div id="resultContainer" class="result-container">
<h2>Quiz Completed!</h2>
<p>Your score:</p>
<div class="score" id="finalScore">0</div>
<button id="restartBtn" class="btn btn-custom">Restart Quiz</button>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// DOM Elements
const rulesBtn = document.getElementById('rulesBtn');
const startBtn = document.getElementById('startBtn');
const rulesContainer = document.getElementById('rulesContainer');
const quizSection = document.getElementById('quizSection');
const questionText = document.getElementById('questionText');
const optionsContainer = document.getElementById('optionsContainer');
const nextBtn = document.getElementById('nextBtn');
const currentQuestionEl = document.getElementById('currentQuestion');
const progressBar = document.getElementById('progressBar');
const timerEl = document.getElementById('timer');
const resultContainer = document.getElementById('resultContainer');
const finalScoreEl = document.getElementById('finalScore');
const restartBtn = document.getElementById('restartBtn');
// Quiz data
const quizData = [
{
question: "What is the capital of France?",
options: ["London", "Berlin", "Paris", "Madrid"],
correctAnswer: 2
},
{
question: "Which planet is known as the Red Planet?",
options: ["Venus", "Mars", "Jupiter", "Saturn"],
correctAnswer: 1
},
{
question: "What is the largest mammal in the world?",
options: ["Elephant", "Giraffe", "Blue Whale", "Polar Bear"],
correctAnswer: 2
},
{
question: "Which element has the chemical symbol 'O'?",
options: ["Gold", "Oxygen", "Osmium", "Oganesson"],
correctAnswer: 1
},
{
question: "Who painted the Mona Lisa?",
options: ["Vincent van Gogh", "Pablo Picasso", "Michelangelo", "Leonardo da Vinci"],
correctAnswer: 3
}
];
// Quiz state
let currentQuestion = 0;
let score = 0;
let timeLeft = 60;
let timerInterval;
let selectedOption = null;
// Event listeners
rulesBtn.addEventListener('click', toggleRules);
startBtn.addEventListener('click', startQuiz);
nextBtn.addEventListener('click', nextQuestion);
restartBtn.addEventListener('click', restartQuiz);
// Functions
function toggleRules() {
if (rulesContainer.style.display === 'block') {
rulesContainer.style.display = 'none';
rulesBtn.textContent = 'View Rules';
} else {
rulesContainer.style.display = 'block';
rulesBtn.textContent = 'Hide Rules';
}
}
function startQuiz() {
rulesContainer.style.display = 'none';
rulesBtn.style.display = 'none';
startBtn.style.display = 'none';
quizSection.style.display = 'block';
loadQuestion();
startTimer();
}
function loadQuestion() {
if (currentQuestion >= quizData.length) {
endQuiz();
return;
}
selectedOption = null;
nextBtn.disabled = true;
const question = quizData[currentQuestion];
questionText.textContent = question.question;
optionsContainer.innerHTML = '';
question.options.forEach((option, index) => {
const optionElement = document.createElement('div');
optionElement.classList.add('option');
optionElement.textContent = option;
optionElement.dataset.index = index;
optionElement.addEventListener('click', selectOption);
optionsContainer.appendChild(optionElement);
});
currentQuestionEl.textContent = currentQuestion + 1;
updateProgress();
}
function selectOption(e) {
const options = document.querySelectorAll('.option');
options.forEach(option => option.classList.remove('selected'));
e.target.classList.add('selected');
selectedOption = parseInt(e.target.dataset.index);
nextBtn.disabled = false;
}
function nextQuestion() {
if (selectedOption !== null) {
if (selectedOption === quizData[currentQuestion].correctAnswer) {
score += 20;
}
currentQuestion++;
if (currentQuestion < quizData.length) {
loadQuestion();
} else {
endQuiz();
}
}
}
function updateProgress() {
const progress = (currentQuestion / quizData.length) * 100;
progressBar.style.width = `${progress}%`;
}
function startTimer() {
timerInterval = setInterval(() => {
timeLeft--;
timerEl.textContent = `${timeLeft}s`;
if (timeLeft <= 0) {
endQuiz();
}
}, 1000);
}
function endQuiz() {
clearInterval(timerInterval);
quizSection.style.display = 'none';
resultContainer.style.display = 'block';
finalScoreEl.textContent = score;
}
function restartQuiz() {
currentQuestion = 0;
score = 0;
timeLeft = 60;
resultContainer.style.display = 'none';
rulesBtn.style.display = 'inline-block';
startBtn.style.display = 'inline-block';
timerEl.textContent = `${timeLeft}s`;
}
// Initialize button state
nextBtn.disabled = true;
});
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Would you like me to explain or break down the code?