Close Menu

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    How to make I Love You Heart Animation using HTML, CSS & JavaScript

    12 September 2026

    How to make Animated Hacker Login/Signup Form using HTML, CSS & JavaScript

    7 September 2026

    How to make Floating Glass Navigation Bar using HTML, CSS & JavaScript

    5 September 2026
    Facebook X (Twitter) Instagram YouTube Telegram Threads
    Coding StellaCoding Stella
    • Home
    • Blog
    • HTML & CSS
      • Login Form
    • JavaScript
    • Hire us!
    Coding StellaCoding Stella
    Home » How to make I Love You Heart Animation using HTML, CSS & JavaScript
    JavaScript

    How to make I Love You Heart Animation using HTML, CSS & JavaScript

    Coding StellaBy Coding Stella12 September 2026No Comments4 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Email WhatsApp Copy Link

    Let’s create a beautiful “I Love You” Heart Animation using HTML, CSS, and JavaScript. It will feature a glowing heart made from multiple “I love you” texts, a smooth 3D rotation effect, and a dark background for a modern romantic look.

    We’ll use:

    • HTML to create the canvas where the heart animation will be displayed.
    • CSS to create the full-screen dark background and make the canvas responsive.
    • JavaScript to generate the heart shape mathematically, add “I love you” text to each point, create the 3D rotation and perspective effects, and animate everything smoothly.

    The heart gradually forms on the screen and continuously rotates in 3D, while the text changes brightness and size based on its depth.

    This project is a simple and fun way to learn how HTML, CSS, and JavaScript work together to create a creative, animated, and interactive visual effect.

    HTML :

    Creates the canvas area where the heart animation will appear and connects the CSS and JavaScript files.

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>I Love you heart animation | @coding.stella</title>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <canvas id="heartCanvas"></canvas>
        <script src="script.js"></script>
    </body>
    </html>

    CSS :

    Makes the canvas full-screen, removes default spacing, sets the background to black, and prevents scrolling.

    * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }
    
    body,
    html {
        width: 100%;
        height: 100%;
        background-color: black;
        overflow: hidden;
    }
    
    canvas {
        display: block;
        width: 100vw;
        height: 100vh;
    }

    JavaScript:

    Creates the 3D “I love you” heart animation. It calculates heart-shaped points using a mathematical formula, adds "I love you" to each point, rotates the heart in 3D, adds perspective and lighting effects, and continuously redraws it to create the animation.

    const canvas = document.getElementById('heartCanvas');
    const ctx = canvas.getContext('2d');
    
    let width, height, viewScale;
    
    function resize() {
        width = canvas.width = window.innerWidth;
        height = canvas.height = window.innerHeight;
        viewScale = Math.min(width, height) / 500;
    }
    window.addEventListener('resize', resize);
    resize();
    
    let points = [];
    let currentScale = 11;
    let i = 0;
    
    function generatePoints() {
        if (currentScale > 16) return;
    
        let angle = i * (Math.PI * 2) / 90;
    
        let x = 16 * Math.pow(Math.sin(angle), 3) * currentScale;
        let y = (13 * Math.cos(angle) - 5 * Math.cos(2 * angle) - 2 * Math.cos(3 * angle) - Math.cos(4 * angle)) * currentScale;
    
        for (let zOffset = -12; zOffset <= 12; zOffset += 12) {
            points.push({
                origX: x,
                origY: y,
                origZ: zOffset,
                text: "I love you"
            });
        }
    
        i++;
        if (i >= 90) {
            i = 0;
            currentScale++;
        }
    
        setTimeout(generatePoints, 70);
    }
    
    let time = 0;
    
    // 2. High-Speed 3D Render Loop
    function render3D() {
        ctx.fillStyle = "black";
        ctx.fillRect(0, 0, width, height);
    
        time += 0.01;
    
        let angleY = time * 1.2;
        let angleX = Math.sin(time * 0.4) * 0.25;
    
        let cosY = Math.cos(angleY);
        let sinY = Math.sin(angleY);
        let cosX = Math.cos(angleX);
        let sinX = Math.sin(angleX);
    
        let projectedPoints = [];
    
        for (let p of points) {
            let x1 = p.origX * cosY - p.origZ * sinY;
            let z1 = p.origX * sinY + p.origZ * cosY;
            let y1 = p.origY;
    
            let y2 = y1 * cosX - z1 * sinX;
            let z2 = y1 * sinX + z1 * cosX;
    
            projectedPoints.push({
                x: x1,
                y: y2,
                z: z2,
                text: p.text
            });
        }
    
        projectedPoints.sort((a, b) => b.z - a.z);
    
        ctx.textAlign = "center";
        ctx.textBaseline = "middle";
    
        for (let p of projectedPoints) {
            let zOffset = 400;
            let perspective = zOffset / (zOffset + p.z);
    
            let drawX = width / 2 + p.x * viewScale * perspective;
            let drawY = height / 2 - p.y * viewScale * perspective;
    
            let lightness = 85 - (p.z / 40) * 25;
    
            // OPTIMIZATION 3: Round values so the browser doesn't struggle caching font/colors
            lightness = Math.max(30, Math.min(100, Math.round(lightness)));
            ctx.fillStyle = `hsl(351, 100%, ${lightness}%)`;
    
            let fontSize = (8.5 * viewScale * perspective).toFixed(1);
            ctx.font = `bold ${fontSize}px Arial`;
    
            ctx.fillText(p.text, drawX, drawY);
        }
    
        requestAnimationFrame(render3D);
    }
    
    setTimeout(generatePoints, 500);
    render3D();
    

    In this project, we created a beautiful “I Love You” 3D Heart Animation using HTML, CSS, and JavaScript. HTML provided the canvas, CSS created the dark background and responsive layout, while JavaScript handled the heart shape, text, 3D rotation, and smooth animation. This project shows how simple web technologies can be combined to create creative and engaging visual effects.

    This project is a simple and practical way to understand how HTML, CSS, and JavaScript work together to create an interactive and visually engaging web interface.

    If you face any issues with your project, don’t worry! You can grab the source code for this project by clicking the Download button. Ready to kick off your coding journey? Happy coding!

    Animation bar JavaScript menu navigation
    Share. Copy Link Twitter Facebook LinkedIn Email WhatsApp
    Previous ArticleHow to make Animated Hacker Login/Signup Form using HTML, CSS & JavaScript
    Coding Stella
    • Website

    Related Posts

    JavaScript

    How to make Animated Hacker Login/Signup Form using HTML, CSS & JavaScript

    7 September 2026
    JavaScript

    How to make Floating Glass Navigation Bar using HTML, CSS & JavaScript

    5 September 2026
    JavaScript

    Newton’s Light Animations using HTML, CSS & JavaScript

    1 September 2026
    Add A Comment
    Leave A Reply Cancel Reply

    Trending Post

    Master Frontend in 100 Days Ebook

    2 March 202432K Views

    How to make Modern Login Form using HTML & CSS | Glassmorphism

    11 January 202431K Views

    How to make I love you Animation in HTML CSS & JavaScript

    14 February 202424K Views

    How to make Valentine’s Day Card using HTML & CSS

    13 February 202415K Views
    Follow Us
    • Instagram
    • Facebook
    • YouTube
    • Twitter
    ads
    Featured Post

    How to create Apple Liquid Navigation Bar using HTML CSS and JS

    7 June 2026

    How to make Animated Download Button in HTML CSS & JS

    21 November 2025

    How to make Animated Login form with Changing Background in HTML & CSS

    12 March 2026

    How to Create Skeleton Loading Animation in HTML & CSS

    12 January 2024
    Latest Post

    How to make I Love You Heart Animation using HTML, CSS & JavaScript

    12 September 2026

    How to make Animated Hacker Login/Signup Form using HTML, CSS & JavaScript

    7 September 2026

    How to make Floating Glass Navigation Bar using HTML, CSS & JavaScript

    5 September 2026

    Newton’s Light Animations using HTML, CSS & JavaScript

    1 September 2026
    Facebook X (Twitter) Instagram YouTube
    • About Us
    • Privacy Policy
    • Return and Refund Policy
    • Terms and Conditions
    • Contact Us
    • Buy me a coffee
    © 2026 Coding Stella. Made with 💙 by @coding.stella

    Type above and press Enter to search. Press Esc to cancel.

    Ad Blocker Enabled!
    Ad Blocker Enabled!
    Looks like you're using an ad blocker. We rely on advertising to help fund our site.
    Okay! I understood