<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Random Quote Generator</title>
<link href="https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;700&family=Lato:wght@300;400&display=swap" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Lato', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 20px;
color: #fff;
}
.quote-container {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 20px;
padding: 40px 30px;
max-width: 600px;
width: 100%;
text-align: center;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
transition: all 0.3s ease;
opacity: 1;
transform: translateY(0) scale(1);
}
#quote {
font-family: 'Playfair Display', serif;
font-size: 2rem;
font-weight: 400;
line-height: 1.4;
margin-bottom: 20px;
opacity: 1;
}
#author {
font-size: 1.2rem;
font-weight: 300;
opacity: 0.9;
font-style: italic;
}
.new-quote-btn {
background: rgba(255, 255, 255, 0.2);
border: none;
color: #fff;
padding: 12px 30px;
font-size: 1.1rem;
font-weight: 400;
border-radius: 50px;
cursor: pointer;
margin-top: 30px;
transition: all 0.3s ease;
backdrop-filter: blur(10px);
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}
.new-quote-btn:hover {
background: rgba(255, 255, 255, 0.3);
transform: translateY(-2px);
box-shadow: 0 15px 30px rgba(0, 0, 0, 0.3);
}
.new-quote-btn:active {
transform: translateY(0);
}
/* Animations */
@keyframes fadeOut {
to {
opacity: 0;
transform: translateY(20px) scale(0.95);
}
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(-20px) scale(1.05);
}
to {
opacity: 1;
transform: translateY(0) scale(1);
}
}
.quote-container.fade-out {
animation: fadeOut 0.6s ease-out forwards;
}
.quote-container.fade-in {
animation: fadeIn 0.6s ease-out forwards;
}
/* Responsive */
@media (max-width: 768px) {
#quote {
font-size: 1.5rem;
}
.quote-container {
padding: 30px 20px;
}
}
</style>
</head>
<body>
<div class="quote-container" id="quoteContainer">
<blockquote id="quote">Click "New Quote" to get started!</blockquote>
<cite id="author">— Sherlock</cite>
</div>
<button class="new-quote-btn" id="newQuoteBtn">New Quote</button>
<script>
const quoteContainer = document.getElementById('quoteContainer');
const quoteEl = document.getElementById('quote');
const authorEl = document.getElementById('author');
const newQuoteBtn = document.getElementById('newQuoteBtn');
async function fetchQuote() {
try {
const response = await fetch('https://api.quotable.io/random');
if (!response.ok) throw new Error('API error');
const data = await response.json();
return {
text: data.content,
author: data.author || 'Anonymous'
};
} catch (error) {
console.error('Failed to fetch quote:', error);
return {
text: 'The life of man is of no greater duration than the breath of his nostrils.',
author: 'Plato'
};
}
}
function updateQuote(quoteObj) {
quoteEl.textContent = quoteObj.text;
authorEl.textContent = `— ${quoteObj.author}`;
}
async function handleNewQuote() {
// Prevent multiple rapid clicks
newQuoteBtn.disabled = true;
newQuoteBtn.textContent = 'Loading...';
// Fade out
quoteContainer.classList.add('fade-out');
quoteContainer.classList.remove('fade-in');
// Wait for fade out to complete, then fetch and fade in
const handleFadeOutEnd = async () => {
quoteContainer.removeEventListener('animationend', handleFadeOutEnd);
const quote = await fetchQuote();
updateQuote(quote);
// Reset and fade in
quoteContainer.classList.remove('fade-out');
quoteContainer.classList.add('fade-in');
const handleFadeInEnd = () => {
quoteContainer.removeEventListener('animationend', handleFadeInEnd);
newQuoteBtn.disabled = false;
newQuoteBtn.textContent = 'New Quote';
};
quoteContainer.addEventListener('animationend', handleFadeInEnd);
};
quoteContainer.addEventListener('animationend', handleFadeOutEnd);
}
// Initial quote on load
async function loadInitialQuote() {
const quote = await fetchQuote();
updateQuote(quote);
quoteContainer.classList.add('fade-in');
}
// Event listeners
newQuoteBtn.addEventListener('click', handleNewQuote);
// Load initial quote
loadInitialQuote();
</script>
</body>
</html>
This is a complete, self-contained HTML file for a random quote generator. It fetches quotes from the Quotable API (https://api.quotable.io/random), features smooth fade-out/fade-in animations with scale transforms for transitions, and includes responsive design, glassmorphism styling, and loading states. Copy-paste into a .html file and open in any modern browser!