How to create random images Just use an array of images . Example: <script type="text/javascript"> var imgArray = ['img1.jpg','img2.jpg','img3.jpg','img4.jpg','img5.jpg' ]; var num = Math.floor( Math.random() * imgArray.length ); var img = imgAr[ num ]; var imgStr = '<img src="' + img + '" alt = "Random Image" width="100%">'; document.write(imgStr); </script> Tweet Share Share Share Share