Random background image script generator

The form below can be used to generate a block of Javascript that can be included on any page to provide dynamic, random background images to any page element with an id value.

If you are looking for a PHP server side solution read CSS Random Background Image Rotation.


  1. Enter the id value of the element you wish to apply the background to. For example, if you have a div element with an id value of wrapper, e.g, <div id=”wrapper”>, enter wrapper in the Element ID field.
  2. Enter either a relative path, or full URL to the image to be used for the background. For example, the logo for this site can be referenced as:
    • /wp-content/themes/k2/styles/thoughtafter/sign.jpg a path relative to the root of this site, or
    • http://www.somesite.com/images/imagename.jpg a full URL

    Enter the path/URL value in the URL of image field. Click the add another image link to enter more images.

  3. Click the Generate Script button, and the complete Javascript block will be displayed in the textarea.
  4. Copy the complete generated script block and paste into the <head> section of your web page, immediately before the closing </head> tag.

If you have comments or feedback about this tool please leave them at this post.

2 comments on “Random background image script generator

Comments are closed.