Min Portfolio Logo
Pixel image piece 1
Pixel image piece 2
Pixel image piece 3
Pixel image piece 4
Pixel image piece 5
Pixel image piece 6
Pixel image piece 7
Pixel image piece 8
Pixel image piece 9
Pixel image piece 10
Pixel image piece 11
Pixel image piece 12
Pixel image piece 13
Pixel image piece 14
Pixel image piece 15
Pixel image piece 16
Pixel image piece 17
Pixel image piece 18
Pixel image piece 19
Pixel image piece 20
Pixel image piece 21
Pixel image piece 22
Pixel image piece 23
Pixel image piece 24
Pixel image piece 25
Pixel image piece 26
Pixel image piece 27
Pixel image piece 28
Pixel image piece 29
Pixel image piece 30
Pixel image piece 31
Pixel image piece 32
Pixel image piece 33
Pixel image piece 34
Pixel image piece 35
Pixel image piece 36
Pixel image piece 37
Pixel image piece 38
Pixel image piece 39
Pixel image piece 40
Pixel image piece 41
Pixel image piece 42
Pixel image piece 43
Pixel image piece 44
Pixel image piece 45
Pixel image piece 46
Pixel image piece 47
Pixel image piece 48
Pixel image piece 49
Pixel image piece 50
Pixel image piece 51
Pixel image piece 52
Pixel image piece 53
Pixel image piece 54
Pixel image piece 55
Pixel image piece 56
Pixel image piece 57
Pixel image piece 58
Pixel image piece 59
Pixel image piece 60
Pixel image piece 61
Pixel image piece 62
Pixel image piece 63
Pixel image piece 64

Pure CSS Floating Hearts Animation Background – Valentine's Day Effect

Author avatar

Chau

1 min read
0

With Valentine's Day approaching, a subtle yet eye-catching floating hearts animation can transform any webpage into a romantic experience. This pure CSS effect creates hearts that gently rise from the bottom of the screen, fade in and out, and drift upward – all without a single line of JavaScript.

This animation is performant, easy to implement, and fully customizable. It's great for personal sites, greeting cards, or themed promotions.


Why Choose This Pure CSS Approach?

  • No external libraries or JavaScript needed.
  • Smooth performance even on mobile devices.
  • Fully responsive and works on any screen size.
  • Simple to tweak for different moods (e.g., pastel colors for softness or vibrant reds for passion).


Step 1: HTML Structure

Start with a minimal HTML file. We'll use multiple <div> elements with the class heart to create individual animated hearts.


HTML
1<!DOCTYPE html>
2<html lang="en">
3<head>
4    <meta charset="UTF-8">
5    <meta name="viewport" content="width=device-width, initial-scale=1.0">
6    <title>Floating Hearts Background</title>
7    <link rel="stylesheet" href="styles.css">
8</head>
9<body>
10    <div class="heart"></div>
11    <div class="heart"></div>
12    <div class="heart"></div>
13    <div class="heart"></div>
14    <div class="heart"></div>
15    <div class="heart"></div>
16    <div class="heart"></div>
17    <div class="heart"></div>
18    <div class="heart"></div>
19    <div class="heart"></div>
20    <div class="heart"></div>
21    <div class="heart"></div>
22</body>
23</html>


Tip: Add more `<div class="heart"></div>` elements for a denser effect (15–20 works well).


Step 2: CSS – Heart Shape and Animation

The heart shape is created using pseudo-elements (::before and ::after). The animation moves hearts upward with fade-in/fade-out.


CSS
1body {
2    margin: 0;
3    height: 100vh;
4    background: #110011; /* Dark background for contrast */
5    overflow: hidden;
6}
7
8.heart {
9    position: absolute;
10    width: 100px;
11    height: 90px;
12    bottom: -100px;
13    animation: float linear infinite;
14}
15
16/* Heart shape using pseudo-elements */
17.heart::before,
18.heart::after {
19    content: '';
20    position: absolute;
21    width: 52px;
22    height: 80px;
23    background: #ff69b4; /* Default pink */
24    border-radius: 50px 50px 0 0;
25    transform: rotate(-45deg);
26    transform-origin: 0 100%;
27    left: 50px;
28}
29
30.heart::after {
31    left: 0;
32    transform: rotate(45deg);
33    transform-origin: 100% 100%;
34}
35
36/* Floating animation */
37@keyframes float {
38    0% {
39        transform: translateY(0);
40        opacity: 0;
41    }
42    10% {
43        opacity: 1;
44    }
45    90% {
46        opacity: 1;
47    }
48    100% {
49        transform: translateY(-120vh);
50        opacity: 0;
51    }
52}
53
54/* Variations using nth-child for position, size, speed, delay, and color */
55.heart:nth-child(1) { left: 5%; animation-duration: 18s; animation-delay: 1s; transform: scale(0.8); }
56.heart:nth-child(1)::before, .heart:nth-child(1)::after { background: #ff1493; }
57
58.heart:nth-child(2) { left: 15%; animation-duration: 15s; animation-delay: 3s; transform: scale(1.2); }
59
60.heart:nth-child(3) { left: 25%; animation-duration: 20s; animation-delay: 6s; transform: scale(0.9); }
61.heart:nth-child(3)::before, .heart:nth-child(3)::after { background: #ff69b4; }
62
63.heart:nth-child(4) { left: 35%; animation-duration: 14s; animation-delay: 2s; transform: scale(1.1); }
64
65.heart:nth-child(5) { left: 45%; animation-duration: 22s; animation-delay: 8s; transform: scale(0.7); }
66.heart:nth-child(5)::before, .heart:nth-child(5)::after { background: #ffb6c1; }
67
68.heart:nth-child(6) { left: 55%; animation-duration: 16s; animation-delay: 4s; transform: scale(1.3); }
69
70.heart:nth-child(7) { left: 65%; animation-duration: 19s; animation-delay: 7s; transform: scale(1); }
71.heart:nth-child(7)::before, .heart:nth-child(7)::after { background: #ff69b4; }
72
73.heart:nth-child(8) { left: 75%; animation-duration: 17s; animation-delay: 0s; transform: scale(0.9); }
74
75.heart:nth-child(9) { left: 85%; animation-duration: 21s; animation-delay: 5s; transform: scale(1.1); }
76.heart:nth-child(9)::before, .heart:nth-child(9)::after { background: #db7093; }
77
78.heart:nth-child(10) { left: 95%; animation-duration: 13s; animation-delay: 9s; transform: scale(0.8); }
79
80.heart:nth-child(11) { left: 10%; animation-duration: 20s; animation-delay: 2s; transform: scale(1.2); }
81
82.heart:nth-child(12) { left: 50%; animation-duration: 18s; animation-delay: 10s; transform: scale(1); }
83.heart:nth-child(12)::before, .heart:nth-child(12)::after { background: #ff1493; }


Screenshot 2026-02-12 110653.png

Customization Tips

  • Change colors: Modify the background property in ::before and ::after.
  • Adjust density: Add more hearts and vary left percentages.
  • Speed & timing: Tweak animation-duration and animation-delay.
  • Background: Use a gradient like background: linear-gradient(to top, #330033, #000000); for a dreamy effect.


Key Points

  • Pure CSS implementation ensures fast loading and broad compatibility.
  • Hearts are created using clever pseudo-element positioning – no images needed.
  • Animation uses @keyframes for smooth upward floating and fading.
  • Easily scalable for different screen sizes.
  • Variations in size, color, speed, and delay create a natural, organic feel.
  • Ideal for seasonal themes like Valentine's Day (or weddings/anniversaries).


Conclusion

Add this floating hearts animation to your next project for an instant romantic upgrade. Copy the code, experiment with customizations, and share your creations on platforms like CodePen or dev.to. Happy Valentine's Day – happy coding! 💕

Comments

0 comments

Loading posts from the same author...

OPEN TO WORK • OPEN TO WORK •
KatX

FROM IDEA TO INNOVATION

LET'S BUILD IT TOGETHER!

I'm available for custom development & SaaS projects.

I thrive on crafting innovative digital solutions, and
delivering exceptional user experiences.