How to Create Fishbowl – Save the fish using HTML, CSS and JavaScript

Let’s create a “Fishbowl – Save the Fish” project using HTML, CSS, and JavaScript. This interactive project will feature a fish that users can “save” by clicking on it, moving it to a safe part of the screen.
We’ll use HTML to structure the fishbowl and fish, CSS to style them and create a visually appealing scene, and JavaScript to add interactivity for saving the fish.
Let’s get started on building the “Fishbowl – Save the Fish” project. Whether you’re a beginner or an experienced developer, this project offers a fun way to practice your web development skills and create an engaging user experience. Let’s dive in!
HTML :
This HTML code creates a fishbowl animation on a webpage. It includes various div elements to represent parts of the fishbowl such as the pool, background, bottom, seaweed decorations, water, and a fish with a tail. It also features an interactive tap to “refill” the fishbowl, prompting animation and style changes defined in an external CSS file (`style.css`). A linked JavaScript file (`script.js`) will handle interactive behaviors.
CSS :
This CSS code creates an animated fishbowl on a webpage. It sets font sizes based on viewport height and centers content using flexbox. It defines animations for a fish (`swimming` and `dead` keyframes) and styles various fishbowl components, including the background, water, and decorations like seaweed. Additionally, it animates fish and water tap elements and adjusts the layout for smaller screens.
JavaScript:
This JavaScript code manages the water level in the fishbowl and the fish’s state. It decreases the water level (`fill`) by 1 every 200ms, updating the fishbowl’s visual state using CSS variables. If the water level drops below certain thresholds, the fish’s state changes to “dying” or “dead”. Clicking the tap refills the water by 20 units (up to a maximum of 90) and reactivates the emptying interval if the fishbowl was empty. The tap also animates briefly when clicked.
In conclusion, creating the “Fishbowl – Save the Fish” project using HTML, CSS, and JavaScript has been an enjoyable and educational journey. By combining HTML for structure, CSS for styling, and JavaScript for interactivity, we’ve crafted a fun and engaging experience where users can interact with the fishbowl to save the fish.
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!