Random Image Script: Modern Alternatives

The original Random Image displayed rotating banners and photos. Today, JavaScript carousels and image APIs offer dynamic, animated solutions.

Image Display

JavaScript Image Carousels

Swiper

Modern mobile touch slider. Framework agnostic (React, Vue, Angular support). Hardware accelerated transitions, lazy loading.

Free MIT License Touch support All frameworks
Splide

Lightweight, flexible slider. No dependencies, TypeScript support. Multiple slides, thumbnails, video support.

Free MIT License ~29KB
Glide.js

Dependency-free ES6 slider. Modular design, small footprint. Keyboard navigation, responsive breakpoints.

Free MIT License ~23KB

Random Image APIs

Unsplash API

Beautiful, free images API. High-quality photos from professional photographers. Random endpoint, search, and collections.

Free (50 req/hr) Production: apply High quality
Lorem Picsum

Easy placeholder images. Simple URL-based API, no authentication. Specify dimensions, blur, grayscale in URL.

Free No API key URL-based
<img src="https://picsum.photos/400/300?random">
Placekitten

Placeholder images of kittens. Simple URL-based, great for development and testing.

Free Cats!

Simple JavaScript Solution

Random Image from Array
const images = [
  'image1.jpg',
  'image2.jpg',
  'image3.jpg'
];

const randomIndex = Math.floor(Math.random() * images.length);
document.getElementById('banner').src = images[randomIndex];

// Or with CSS background:
document.body.style.backgroundImage =
  `url('${images[randomIndex]}')`;

Feature Comparison

Feature Random Image CGI Modern Solutions
TransitionsNoneCSS/JS animations
Lazy loadingNoBuilt-in
Touch/SwipeNoYes
ResponsiveNoYes
ThumbnailsNoYes
AutoplayPage refreshContinuous
Server loadEach requestClient-side

Recommendation

Full-featured: Swiper

Lightweight: Splide or Glide.js

API images: Unsplash

Placeholders: Lorem Picsum

NPM Install

npm install swiper
npm install @splidejs/splide
npm install @glidejs/glide
All Examples Random Image Overview