# How can I get HTML/CSS to display a randomly selected image?

**URL:** <https://forum.kirupa.com/t/how-can-i-get-html-css-to-display-a-randomly-selected-image/183701>\
**Category:** web dev\
**Created:** [March 29, 2006, 10:31am UTC](https://forum.kirupa.com/t/how-can-i-get-html-css-to-display-a-randomly-selected-image/183701 "2006-03-29T10:31:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![spindrift](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@spindrift](https://forum.kirupa.com/u/spindrift)\
**Post date:** [March 29, 2006, 10:31am UTC](https://forum.kirupa.com/t/how-can-i-get-html-css-to-display-a-randomly-selected-image/183701/1 "2006-03-29T10:31:42Z")

</div>

Hi guys,

I’m using Dreamweaver MX 2004 to create an HTML website.

I have a series of header images in a folder all with the same dimensions. What I want to be able to do is have one of these images, selected at random, to appear in a certain place everytime a new page is loaded.

From what I know, I believe this may be possible using CSS?

Any help would be much appreciated. Thank you very much and I hope to hear from you.

All the best,

Mark

---

<div class="post-metadata">

**Author:** ![bwh2](https://avatars.discourse-cdn.com/v4/letter/b/8c91f0/32.png) [@bwh2](https://forum.kirupa.com/u/bwh2)\
**Post date:** [March 29, 2006, 3:08pm UTC](https://forum.kirupa.com/t/how-can-i-get-html-css-to-display-a-randomly-selected-image/183701/2 "2006-03-29T15:08:14Z")

</div>

you need to either use something server-side like php or asp, or something client-side like javascript. css and html alone won’t do it.

---

<div class="post-metadata">

**Author:** ![RabBell](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rabbell/32/340_2.png) [@RabBell](https://forum.kirupa.com/u/RabBell)\
**Post date:** [March 30, 2006, 1:53pm UTC](https://forum.kirupa.com/t/how-can-i-get-html-css-to-display-a-randomly-selected-image/183701/3 "2006-03-30T13:53:15Z")

</div>

using javascript I would place the images in an array and then randomly select one from the array

try here for help  
[http://www.w3schools.com/js/default.asp](http://www.w3schools.com/js/default.asp)

but it can’t be done with just CSS, using Javascript though does make it DHTML so if you know HTML & CSS, learn javascript and it means you can add DHTML to your CV…2 for 1 :thumb:

---

<div class="post-metadata">

**Author:** ![spindrift](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@spindrift](https://forum.kirupa.com/u/spindrift)\
**Post date:** [March 31, 2006, 1:24pm UTC](https://forum.kirupa.com/t/how-can-i-get-html-css-to-display-a-randomly-selected-image/183701/4 "2006-03-31T13:24:33Z")

</div>

that’s brilliant!

thanks guys - much appreciated.

all the best,

mark
