๐Ÿ’ก Bulb Toggle Project Using HTML, CSS & JavaScript



This content originally appeared on DEV Community and was authored by Olayemi Habeeb

๐Ÿ’ก Bulb Toggle Project Using HTML, CSS & JavaScript

Hey devs ๐Ÿ‘‹๐Ÿฝ

I recently built a simple Bulb Toggle Project as part of my learning journey.

Even though I’m focused on backend development, I challenged myself to create a small frontend-based project using HTML, CSS, and JavaScript โ€” and it turned out to be both fun and educational.

โš™ What the Project Does

The idea is simple:

A lightbulb turns on and off when you click a button.

This helped me understand:

  • DOM manipulation in JavaScript
  • Basic CSS styling
  • How HTML structure connects with logic

๐Ÿ›  Tools & Languages Used

  • HTML (structure)
  • CSS (styling the bulb and page)
  • JavaScript (to handle the toggle logic)

๐Ÿ’ป How It Works

  • There’s a bulb image (off state by default).
  • A button controls the bulb.
  • When clicked, JavaScript changes the image to the “on” or “off” version.

Hereโ€™s a quick view of the logic in JavaScript:


js
let bulb = document.getElementById("bulb");
let btn = document.getElementById("btn");

btn.addEventListener("click", () => {
  if (bulb.src.includes("bulb-off")) {
    bulb.src = "bulb-on.png";
    btn.innerText = "Turn Off";
  } else {
    bulb.src = "bulb-off.png";
    btn.innerText = "Turn On";
  }
});

Simple, right? But it taught me a lot about DOM events and conditions.


🎯 What I Learned

As a backend newbie, this project helped me:
    โ€ข Get comfortable manipulating the DOM
    โ€ข Build logic without frameworks
    โ€ข Appreciate how frontend and backend work together


## Video

https://www.instagram.com/p/DLTG_s_s54v/?igsh=dnlpbnEydTI1aHk1



👨🏽‍💻 About Me

Iโ€™m a backend development learner from Nigeria 🇳🇬
Learning one bug and project at a time 😅
Currently working with Node.js, Express, and MongoDB.
Letโ€™s connect!


✅ Want to Build It Too?

This project is perfect for beginners. You only need:
    โ€ข A text editor (like VS Code)
    โ€ข A browser to test it
    โ€ข Some patience and curiosity 😉



Thanks for reading!

Feel free to share feedback or ask me how I did certain parts.
You can also follow my journey here on DEV or connect via Hashnode: anizoomy.hashnode.dev

Happy coding! 💡


This content originally appeared on DEV Community and was authored by Olayemi Habeeb