Ocean waves at sunset, a 12 second loop in SVG and CSS
Four rows of waves roll past a small boat at sunset while the gulls flap and the clouds drift. It loops every 12 seconds with no seam.
Motion loop
A sea that never stops
Sundry Millsundrymill.com/library
Download
The sky, the sea and the boat
-
Sunset sky
-
Sun
-
Far sea
-
Mid sea
-
Deep sea
-
Hull
The code
The trick: slide each wave by exactly one wavelength
/* each wave path is drawn wider than the view, then moved sideways by one
wavelength; at the end of the move it looks the same as at the start */
.sea-w1 { animation: sea-w1 6s linear infinite; } /* wavelength 60, 2 trips in 12 s */
.sea-w4 { animation: sea-w4 12s linear infinite; } /* wavelength 180, 1 trip in 12 s */
@keyframes sea-w1 { to { transform: translateX(-60px); } }
@keyframes sea-w4 { to { transform: translateX(180px); } }
/* every other duration divides 12 s too, so the whole scene repeats every 12 s */
.sea-boat { transform-box: fill-box; transform-origin: 50% 100%; animation: sea-rock 4s ease-in-out infinite; }
@keyframes sea-rock {
0%, 100% { transform: translateY(0) rotate(-4deg); }
50% { transform: translateY(5px) rotate(4deg); }
}
How each wave is drawn (run once, paste the path)
// y: the water line, amp: wave height, period: wavelength, in SVG units
function wave(y, amp, period, from = -period, to = 360 + period) {
let d = 'M' + from + ' ' + y + ' Q' + (from + period / 4) + ' ' + (y - amp) + ' ' + (from + period / 2) + ' ' + y;
for (let x = from + period / 2; x < to; x += period / 2) d += ' T' + (x + period / 2) + ' ' + y;
return d + ' L' + to + ' 440 L' + from + ' 440 Z';
}
console.log(wave(390, 12, 180));
How to use it
- A T command in an SVG path repeats the last curve mirrored, so one Q and a run of T points draw a smooth, even wave of any length.
- The waves move left and right in turn. Real waves roll toward you, but alternating directions reads as a choppy sea and keeps the eye moving.
- For anyone who asks for reduced motion, everything stops on the first frame and the picture stays.
- To record it as a video, open the file full screen and screen record 12 seconds; the last frame matches the first.
When to use it
- A calm hero or header for a travel, holiday, seaside or wellness site, where a photo would be heavy and a video would be several megabytes.
- Loop content for social posts and Pinterest pins: screen record 12 seconds and it loops with no jump.
- Not behind body text. Moving water under words makes them harder to read; give the scene its own space and put the words beside or below it.
A worked example: a hero for a sailing school
The loop at the top of a sailing school's home page, with the headline below it and the motion paused for anyone who prefers less of it.
- Paste the SVG and its CSS into the page, or put the downloaded file in an iframe if you want to keep it apart from your own styles.
- Give the SVG a role="img" and an aria-label that says what it shows, as this one does. Screen readers then hear one sentence instead of a list of shapes.
- Set the headline below the scene in Deep Sea #284C8C on white, 8.4:1, so the text never sits on moving water.
- Keep the reduced motion block. It pauses every part on its first frame, so the hero becomes a still picture of the same scene.
Free to use in personal and commercial work. No credit needed, though a link back is always nice.