Anand Anand - 1 year ago 185
HTML Question

Change image onclick and again change to previous image on clicking again - only using CSS and HTML

I have tried following code which is onclicking an image it changes to another image and again it should switch back to previous image on clicking again. In below code the image will only stay visible while you are holding down the mouse button. I want to have it stay visible until you click again.

<!DOCTYPE html>
<head><title>HTML5 form</title><link rel="SHORTCUT ICON" href="/e/ref.ico" />
<style type="text/css">
div.nav {
height: 340px;
width: 300px;

div.nav a, div.nav a:link, div.nav a:visited {

div.nav img {

div.nav a:active img {
.thumbnail:focus span
visibility: visible;
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'></head>
<div class="nav">
<a href="#">
<img src="" alt="" />

Answer Source

Try this:

<!DOCTYPE html>
    <style type="text/css">
        .checkbox { display: none; }
        .label {
            display: inline-block;
            width: 100px;
            height: 100px;
            background: url(;
        .checkbox:checked + .label {
            background: url(;
    <input type="checkbox" class="checkbox" id="checked">
    <label class="label" for="checked"></label>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download