Close Menu

    Subscribe to Updates

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

    What's Hot

    How to create 3D Liquid Toggle using HTML CSS and JS

    11 June 2026

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

    7 June 2026

    How to make Futuristic 3D Folder Animation using HTML and CSS

    5 June 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 create 3D Liquid Toggle using HTML CSS and JS
    JavaScript

    How to create 3D Liquid Toggle using HTML CSS and JS

    Coding StellaBy Coding Stella11 June 2026Updated:11 June 2026No Comments3 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Email WhatsApp Copy Link

    Let’s create a 3D Liquid Toggle using HTML, CSS, and JavaScript to build a smooth and interactive toggle switch with realistic liquid-style animations and 3D effects. In this project, we’ll create a visually appealing toggle that uses a 3D liquid object to simulate fluid movement when switched on or off.

    We’ll use:

    • HTML: To create the canvas container where the 3D liquid toggle is displayed and load the required libraries.
    • CSS: To style the page layout, center the 3D scene, make the canvas responsive, and create a clean background that highlights the liquid effect.
    • JavaScript: To load and control the 3D liquid scene using Spline, handle animations with GSAP, and manage object interactions for smooth toggle transitions.

    This project is perfect for learning 3D web design, Spline integration, GSAP animations, interactive UI effects, and creating modern toggle components using HTML, CSS, and JavaScript.nd building premium-looking navigation components for websites.

    HTML :

    The HTML creates a container with a <canvas> element where the 3D animation is displayed. It also connects the CSS file for styling, the GSAP library for animations, and the JavaScript file that loads the 3D scene.

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="UTF-8">
      <title>3D Liquid Toggle | @coding.stella</title>
      <link rel="stylesheet" href="https://public.codepenassets.com/css/normalize-5.0.0.min.css">
      <link rel="stylesheet" href="./style.css">
    </head>
    
    <body>
      <div id='container'>
        <canvas id="canvas3d"></canvas>
      </div>
      <script src='https://unpkg.com/gsap@3/dist/gsap.min.js'></script>
      <script type="module" src="./script.js"></script>
    
    </body>
    </html>

    CSS :

    The CSS removes the default page margin, hides scrollbars, and sets a light gray background color. It also makes the canvas fill the entire screen and centers the 3D content properly.

    body {
      background-color: #DDDDDF;
      margin: 0;
      overflow: hidden;
    }
    
    #container {
      display: flex;
      justify-content: center;
      align-items: flex-start;
      height: 100% !important;
    
    }
    
    #canvas3d {
      width: 100% !important;
      height: 100% !important;
    }

    JavaScript:

    The JavaScript loads a 3D scene from Spline into the canvas, creates helper functions for calculations and object handling, and initializes GSAP for animations. After the scene loads, it prepares the objects so they can be animated and interacted with.

    const fileName = "UrQ5NC7ZjIIFJb7O";
    
    function r2d(r) {
      return r * (180 / Math.PI);
    }
    function d2r(d) {
      return d * (Math.PI / 180);
    }
    function objectArray(all, name) {
      return all.filter(item => item.name == name)
    }
    function getDuplicateNameObjects(app, obj, name) {
      if (new RegExp(name).test(obj.name)) {
        return true
      }
    }
    //   if(getDuplicateNameObjects(app, c, 'Shape')){
    //    shapeObjArr.push(c);
    // }
    const timelineObject = {
      repeat: -1,
      defaults: {
        ease: 'elastic(0.5, 0.43)',
        duration: 1
      }
    }
    import { Application } from "https://esm.sh/@splinetool/runtime";
    const canvas = document.getElementById('canvas3d');
    const app = new Application(canvas);
    //const myVariables = { displayText: 'Chris!', mySize: 350 };
    app.load(`https://prod.spline.design/${fileName}/scene.splinecode`)
      .then(() => {
    
        //const labelGroup = app.findObjectByName('labelGroup');
        //let allObjects = app.getAllObjects();
    
    
        //let objArr = objectArray(allObjects, 'name')
    
        let mainTl = gsap.timeline();
        /*
            objArr.forEach((i, c) => {
              console.log(i, c)
        
            })
          */
        //const obj = spline.findObjectById('7AF5EBC0-09BB-4720-B045-F478F8053AA4');
    
        //console.log(binPopupArray); // Spline Object => { name: 'Cube', id: '7AF5EBC0-09BB-4720-B045-F478F8053AA4', position: {}, ... }
    
      });

    In conclusion, we successfully created a 3D Liquid Toggle using HTML, CSS, and JavaScript, combining modern web technologies with interactive 3D design. By using Spline for the 3D scene and GSAP for animations, we achieved a smooth liquid-like toggle effect that feels both realistic and engaging. This project is a great way to explore 3D web experiences, animation techniques, and creative UI design, helping you build more modern and visually impressive interfaces for your websites.

    If your project has problems, don’t worry. Just click to download the source code and face your coding challenges with excitement. Have fun coding!

    Animation CSS Animation toggle
    Share. Copy Link Twitter Facebook LinkedIn Email WhatsApp
    Previous ArticleHow to create Apple Liquid Navigation Bar using HTML CSS and JS
    Coding Stella
    • Website

    Related Posts

    JavaScript

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

    7 June 2026
    HTML & CSS

    How to make Futuristic 3D Folder Animation using HTML and CSS

    5 June 2026
    HTML & CSS

    How to make Animated Circular Gallery using HTML and CSS

    1 June 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 make Magic Mouse Effect using HTML CSS & JavaScript

    24 April 2024

    How to make Animated Glowing Bell Button using HTML and CSS

    21 January 2026

    How to make Fancy Glowing Button using HTML & CSS

    24 July 2024

    How to make Juicy Hamburgers Menu using HTML and CSS

    26 December 2025
    Latest Post

    How to create 3D Liquid Toggle using HTML CSS and JS

    11 June 2026

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

    7 June 2026

    How to make Futuristic 3D Folder Animation using HTML and CSS

    5 June 2026

    How to make Animated Circular Gallery using HTML and CSS

    1 June 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