Absolutely! Let's transform your Recipe Generator website into an engaging, modern, and visually stunning application with beautiful animations, transitions, and an enhanced user interface. We'll utilize Tailwind CSS for styling, integrate smooth animations using Tailwind CSS Animate or custom CSS animations, and improve the overall layout for a more intuitive user experience.
Here's the complete redesigned HTML code with detailed explanations of the enhancements:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Delicious Recipe Generator</title>
<!-- Tailwind CSS CDN -->
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@3.3.2/dist/tailwind.min.css" rel="stylesheet">
<!-- Google Fonts for enhanced typography -->
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
<!-- Additional Styles -->
<style>
body {
font-family: 'Inter', sans-serif;
background: linear-gradient(135deg, #f0f4f8 0%, #d9e2ec 100%);
overflow-x: hidden;
}
/* Custom animations */
@keyframes fadeInUp {
from {
opacity: 0;
transform: translate3d(0, 40px, 0);
}
to {
opacity: 1;
transform: translate3d(0, 0, 0);
}
}
.animate-fadeInUp {
animation: fadeInUp 0.6s ease forwards;
}
/* Button ripple effect */
.btn-ripple {
position: relative;
overflow: hidden;
}
.btn-ripple::after {
content: "";
position: absolute;
width: 200%;
height: 200%;
top: 50%;
left: 50%;
background: rgba(255, 255, 255, 0.3);
transform: translate(-50%, -50%) scale(0);
border-radius: 50%;
transition: transform 0.6s, opacity 1s;
pointer-events: none;
}
.btn-ripple:active::after {
transform: translate(-50%, -50%) scale(1);
opacity: 0;
transition: transform 0s, opacity 0.5s;
}
</style>
</head>
<body class="min-h-screen flex items-center justify-center p-4">
<div class="bg-white shadow-2xl rounded-3xl p-10 w-full max-w-2xl transform transition-transform duration-500 hover:scale-105">
<!-- Header with Icon -->
<div class="flex flex-col items-center mb-8 animate-fadeInUp">
<svg xmlns="http://www.w3.org/2000/svg" class="h-16 w-16 text-green-500 mb-4 animate-pulse" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4" />
</svg>
<h1 class="text-4xl font-extrabold text-gray-800">Delicious Recipe Generator</h1>
<p class="text-gray-500 mt-2">Create amazing recipes based on your ingredients</p>
</div>
<!-- Input Form -->
<form class="space-y-6 animate-fadeInUp">
<!-- Ingredients Input -->
<div>
<label for="ingredients" class="block text-gray-700 font-semibold mb-2">Enter Ingredients</label>
<input type="text" id="ingredients" placeholder="e.g., chicken, tomatoes, pasta"
class="w-full px-4 py-3 border border-gray-300 rounded-lg placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-green-500 transition duration-300"
required>
</div>
<!-- OR Divider -->
<div class="flex items-center justify-center text-gray-500">
<span class="px-2">OR</span>
</div>
<!-- Image Upload -->
<div>
<label for="image-upload" class="block text-gray-700 font-semibold mb-2">Upload Ingredient Image</label>
<div class="flex items-center justify-center w-full">
<label class="flex flex-col items-center px-4 py-6 bg-gray-100 text-blue rounded-lg tracking-wide uppercase border border-blue cursor-pointer hover:bg-blue-50 transition duration-300">
<svg class="w-8 h-8" fill="currentColor" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
<path d="M16.88 9.1a3 3 0 010 4.2l-7 7a3 3 0 01-4.2 0l-7-7a3 3 0 014.2-4.2L9 12.79V3a1 1 0 012 0v9.79l4.88-4.88a3 3 0 014.2 0z" />
</svg>
<span class="mt-2 text-base leading-normal">Select Image</span>
<input type="file" id="image-upload" accept="image/*" class="hidden">
</label>
</div>
</div>
<!-- Generate Button -->
<button type="button" onclick="generateRecipes()"
class="w-full bg-green-500 text-white py-3 rounded-lg font-semibold hover:bg-green-600 focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-opacity-50 btn-ripple transition duration-300">
Generate Recipes
</button>
</form>
<!-- Recipe List -->
<div id="recipe-list" class="mt-8 space-y-4 animate-fadeInUp"></div>
<!-- Generate More Recipes Button -->
<div id="generate-more-container" class="mt-6 hidden">
<button onclick="generateMoreRecipes()"
class="w-full bg-blue-500 text-white py-3 rounded-lg font-semibold hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-opacity-50 btn-ripple transition duration-300">
Generate More Recipes
</button>
</div>
<!-- Recipe Details Modal -->
<div id="recipe-details-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden">
<div class="bg-white rounded-2xl p-8 w-full max-w-3xl relative transform transition-all duration-500 animate-fadeInUp">
<button onclick="closeRecipeDetails()" class="absolute top-4 right-4 text-gray-600 hover:text-gray-800 transition duration-300">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
<div id="recipe-details" class="space-y-6 overflow-y-auto max-h-96"></div>
</div>
</div>
</div>
<!-- Overlay for smooth transitions -->
<div id="overlay" class="fixed inset-0 bg-white opacity-0 pointer-events-none transition-opacity duration-700"></div>
<!-- JavaScript Section -->
<script>
let currentIngredients = '';
let generatedRecipes = [];
// Utility function to add loading spinner
function showLoading(container) {
container.innerHTML = `
<div class="flex justify-center items-center">
<svg class="animate-spin h-8 w-8 text-green-500" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8v8H4z"></path>
</svg>
</div>
`;
}
async function generateRecipes(isMoreRecipes = false) {
const ingredientsInput = document.getElementById('ingredients');
const imageUpload = document.getElementById('image-upload');
const recipeList = document.getElementById('recipe-list');
const recipeDetailsModal = document.getElementById('recipe-details-modal');
const generateMoreContainer = document.getElementById('generate-more-container');
// Clear previous content
recipeList.innerHTML = '';
// Show loading spinner
showLoading(recipeList);
// Store current ingredients
currentIngredients = ingredientsInput.value.trim();
const formData = new FormData();
if (currentIngredients) {
formData.append('ingredients', currentIngredients);
}
if (imageUpload.files.length > 0) {
formData.append('image', imageUpload.files[0]);
}
// If generating more recipes, pass previous recipes to avoid duplicates
if (isMoreRecipes && generatedRecipes.length > 0) {
generatedRecipes.forEach(recipe => {
formData.append('previous_recipes[]', recipe);
});
}
try {
const response = await fetch('/generate_recipes', {
method: 'POST',
body: formData
});
const recipes = await response.json();
if (recipes.error) {
recipeList.innerHTML = `<p class="text-red-500 text-center">${recipes.error}</p>`;
return;
}
// Combine or replace recipes based on whether it's initial generation or more recipes
if (!isMoreRecipes) {
generatedRecipes = recipes;
} else {
generatedRecipes = [...generatedRecipes, ...recipes];
}
// Render recipe list
renderRecipeList(recipes);
// Show Generate More button
generateMoreContainer.classList.remove('hidden');
} catch (error) {
console.error('Error:', error);
recipeList.innerHTML = `<p class="text-red-500 text-center">Failed to generate recipes. Please try again.</p>`;
}
}
function renderRecipeList(recipes) {
const recipeList = document.getElementById('recipe-list');
recipeList.innerHTML = ''; // Clear loading spinner or previous errors
if (recipes.length === 0) {
recipeList.innerHTML = `<p class="text-gray-500 text-center">No recipes found. Try different ingredients.</p>`;
return;
}
recipes.forEach(recipe => {
const recipeCard = document.createElement('div');
recipeCard.className = 'bg-green-50 p-6 rounded-xl shadow-md cursor-pointer hover:bg-green-100 transition duration-300 flex items-center space-x-4';
recipeCard.innerHTML = `
<div class="flex-shrink-0">
<svg xmlns="http://www.w3.org/2000/svg" class="h-12 w-12 text-green-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h3.75M9 16h6M9 8h6m6 4a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
</div>
<div>
<h3 class="text-xl font-bold text-gray-800">${recipe}</h3>
</div>
`;
recipeCard.onclick = () => getRecipeDetails(recipe);
recipeList.appendChild(recipeCard);
});
}
function generateMoreRecipes() {
generateRecipes(true);
}
async function getRecipeDetails(recipeName) {
const recipeDetailsModal = document.getElementById('recipe-details-modal');
const recipeDetails = document.getElementById('recipe-details');
// Show modal
recipeDetailsModal.classList.remove('hidden');
document.getElementById('overlay').classList.remove('opacity-0', 'pointer-events-none');
// Show loading spinner
recipeDetails.innerHTML = `
<div class="flex justify-center items-center">
<svg class="animate-spin h-10 w-10 text-green-500" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8v8H4z"></path>
</svg>
</div>
`;
const formData = new FormData();
formData.append('recipe_name', recipeName);
formData.append('ingredients', currentIngredients);
try {
const response = await fetch('/get_recipe_details', {
method: 'POST',
body: formData
});
const details = await response.json();
if (details.error) {
recipeDetails.innerHTML = `<p class="text-red-500 text-center">${details.error}</p>`;
return;
}
// Render recipe details
recipeDetails.innerHTML = `
<h2 class="text-3xl font-bold text-green-600 mb-4">${details.name}</h2>
<div>
<h3 class="text-2xl font-semibold text-gray-700 mb-2">Ingredients</h3>
<ul class="list-disc list-inside text-gray-600">
${details.ingredients.map(ing => `<li>${ing}</li>`).join('')}
</ul>
</div>
<div class="mt-4">
<h3 class="text-2xl font-semibold text-gray-700 mb-2">Instructions</h3>
<ol class="list-decimal list-inside text-gray-600">
${details.instructions.map(step => `<li class="mb-2">${step}</li>`).join('')}
</ol>
</div>
<div class="mt-4 grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<h3 class="text-2xl font-semibold text-gray-700 mb-2">Who Can Eat</h3>
<ul class="list-disc list-inside text-gray-600">
${details.who_can_eat.map(group => `<li>${group}</li>`).join('')}
</ul>
</div>
<div>
<h3 class="text-2xl font-semibold text-gray-700 mb-2">Who Should Avoid</h3>
<ul class="list-disc list-inside text-gray-600">
${details.who_should_avoid.map(group => `<li>${group}</li>`).join('')}
</ul>
</div>
</div>
${details.additional_info ? `
<div class="mt-6">
<h3 class="text-2xl font-semibold text-gray-700 mb-2">Additional Info</h3>
<p class="text-gray-600">${details.additional_info}</p>
</div>
` : ''}
`;
} catch (error) {
console.error('Error:', error);
recipeDetails.innerHTML = `<p class="text-red-500 text-center">Failed to retrieve recipe details. Please try again.</p>`;
}
}
function closeRecipeDetails() {
const recipeDetailsModal = document.getElementById('recipe-details-modal');
const overlay = document.getElementById('overlay');
recipeDetailsModal.classList.add('hidden');
overlay.classList.add('opacity-0', 'pointer-events-none');
}
// Close modal when clicking outside the modal content
window.onclick = function(event) {
const recipeDetailsModal = document.getElementById('recipe-details-modal');
const overlay = document.getElementById('overlay');
if (event.target == recipeDetailsModal || event.target == overlay) {
recipeDetailsModal.classList.add('hidden');
overlay.classList.add('opacity-0', 'pointer-events-none');
}
}
</script>
</body>
</html>
Key Enhancements and Features:
-
Modern Typography and Colors:
- Google Fonts Integration: Switched to the 'Inter' font for better readability and a modern look.
- Enhanced Color Palette: Utilized shades of green and complementary colors to evoke freshness and appetite associated with food.
-
Enhanced Layout and Structure:
- Responsive Design: The layout adapts seamlessly to different screen sizes, ensuring a great experience on both desktop and mobile devices.
- Centered Content: The main container is centered with padding for better focus and aesthetics.
- Clean Separation: Inputs are clearly separated with an "OR" divider for better user guidance.
-
Interactive Elements with Animations:
- Hover Effects: Containers scale slightly on hover to create a dynamic feel.
- Pulse Animation: The header icon pulses subtly to draw attention.
- Fade-In Animations: Sections fade in smoothly when loaded, enhancing the user experience.
- Button Ripple Effect: Added a ripple effect to buttons to provide visual feedback on clicks.
-
Improved User Interface Components:
- SVG Icons: Added relevant icons to enhance visual appeal and guide users.
- Custom File Upload Button: Styled the file upload area to match the overall design and make it more interactive.
- Loading Spinners: Integrated spinners to indicate processing during recipe generation and fetching details.
-
Enhanced Recipe Listing:
- Recipe Cards: Each recipe is displayed as a card with icons and hover effects, making them more engaging and easier to interact with.
-
Modal for Recipe Details:
- Overlay and Modal Window: When a recipe is clicked, a modal window with a semi-transparent overlay appears, focusing the user's attention on the recipe details.
- Smooth Transitions: The modal fades in smoothly, and it can be closed by clicking the close button or outside the modal area.
-
Accessibility Improvements:
- Focus Rings: Added focus rings to input fields and buttons for better accessibility.
Additional Recommendations:
-
Backend Integration: Ensure that your backend endpoints (/generate_recipes and /get_recipe_details) are correctly set up to handle the requests and return the expected JSON responses.
-
Accessibility Testing: Use tools like Lighthouse to audit your website for accessibility and performance improvements.
-
SEO Optimization: Although not the primary focus, consider adding meta tags and structured data to improve the website's search engine visibility.
-
Progressive Enhancement: Ensure that the website remains functional even if JavaScript fails, by providing server-side rendering or graceful degradation.
By implementing these enhancements, your Recipe Generator website will not only look stunning but also provide an engaging and delightful user experience. Feel free to customize further based on your specific requirements and branding guidelines!