Okay, here's an HTML file with "Happy Birthday" animated using CSS. I'll provide a couple of animation styles.
Method 1: Simple Fade-in and Color Change
This version makes the words fade in one after the other and then continuously cycle through some festive colors.
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Happy Birthday!</title>
<link href="https://fonts.googleapis.com/css2?family=Pacifico&display=swap" rel="stylesheet">
<style>
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
background-color: #f0f8ff; /* Light Alice Blue background */
font-family: 'Pacifico', cursive; /* A festive font */
overflow: hidden; /* Hide scrollbars if animation goes off screen slightly */
}
.birthday-text {
text-align: center;
}
.birthday-text h1 {
font-size: 6rem; /* Large text */
margin: 10px 0;
opacity: 0; /* Start invisible for fade-in */
transform: translateY(20px); /* Start slightly down for slide-in effect */
letter-spacing: 2px;
text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}
#happy {
animation: fadeInSlideUp 1s ease-out forwards,
colorCycle 10s linear infinite 1s; /* Start colorCycle after 1s (fade-in duration) */
}
#birthday {
animation: fadeInSlideUp 1s ease-out 0.5s forwards, /* Delay start by 0.5s */
colorCycle 10s linear infinite 1.5s; /* Delay start by 1.5s */
}
/* Keyframes for fade-in and slide-up effect */
@keyframes fadeInSlideUp {
to {
opacity: 1;
transform: translateY(0);
}
}
/* Keyframes for color cycling effect */
@keyframes colorCycle {
0% { color: #FF69B4; } /* Hot Pink */
15% { color: #FFA500; } /* Orange */
30% { color: #FFD700; } /* Gold */
45% { color: #ADFF2F; } /* Green Yellow */
60% { color: #1E90FF; } /* Dodger Blue */
75% { color: #BA55D3; } /* Medium Orchid */
90% { color: #FF1493; } /* Deep Pink */
100% { color: #FF69B4; } /* Back to Hot Pink */
}
/* Responsive adjustments */
@media (max-width: 768px) {
.birthday-text h1 {
font-size: 4rem;
}
}
@media (max-width: 480px) {
.birthday-text h1 {
font-size: 2.8rem;
}
}
</style>
</head>
<body>
<div class="birthday-text">
<h1 id="happy">Happy</h1>
<h1 id="birthday">Birthday!</h1>
</div>
</body>
</html>
How to use it:
Save: Copy the code above and paste it into a plain text file. Save the file with an .html extension (e.g., birthday.html).
Open: Open the saved HTML file in any web browser (like Chrome, Firefox, Safari, Edge).
Explanation:
HTML Structure:
We have a div with class birthday-text to center the content.
Inside, two <h1> tags, one for "Happy" (with id="happy") and one for "Birthday!" (with id="birthday").
CSS Styling (<style> block):
body: Uses Flexbox to perfectly center the text on the page. Sets a background color and a festive font (Pacifico from Google Fonts).
.birthday-text h1:
Sets the initial opacity to 0 (invisible) and transform: translateY(20px) (slightly moved down) so they can fade and slide in.
Defines font size, margins, letter spacing, and a subtle text shadow.
#happy and #birthday:
These apply the animations.
animation: name duration timing-function delay iteration-count direction fill-mode;
fadeInSlideUp animation:
1s: Duration of the animation.
ease-out: Timing function (starts fast, ends slow).
forwards: The element retains the style values from the last keyframe when the animation ends (so it stays visible and in place).
colorCycle animation:
10s: Duration for one full cycle.
linear: Constant speed.
infinite: Repeats forever.
1s (for #happy) / 1.5s (for #birthday): This is an animation-delay for the colorCycle animation. It ensures the color change starts after the fadeInSlideUp animation has completed.
The #birthday animation has an additional 0.5s delay for fadeInSlideUp itself, so "Birthday" appears after "Happy".
@keyframes fadeInSlideUp:
Defines the animation steps. to (or 100%) is the end state: (fully visible) and (back to original vertical position).
This provides a nice, animated "Happy Birthday" message! You can tweak the colors, timings, font sizes, and animation styles to your liking.