How to create Responsive Image Gallery

How to create Responsive Image Gallery

Before We Start

A gallery is one of the main components of a website, It contains links to the other sections and a user interface element within a website. The most important one and the first section that the user sees when he/she enters a website.

How to create Responsive Image Gallery. So if you are a person who wishes to develop a website, you have to know how to create a gallery properly.

How to create Responsive Image Gallery? We are here to solve your problem. In this article we discuss how to create a gallery. Before we start please read the below articles which easier you to understand the process, if you are new to development.

Step 1 – Add HTML

It’s too easy and simple. Just copy and paste below code in your HTML editor between <body> </body> tag.

<div id="gallery" class="container">
	<div class="col-xs-12 no-pad">
		<h3>Image Gallery</h3>
		<hr />

	<div id="gallery-box">
		<div id="gallery-count"><span id="count">1</span> of <span id="total"></span></div>
		<a id="gallery-link" href="" target="_blank">
			<div id="gallery-img">
	<div class="gallery-thumbnails">
		<div class="col-xs-12 no-pad">
			<img id="1" class="img-responsive" src="" />
			<img id="2" class="img-responsive" src="" />
			<img id="3" class="img-responsive" src="" />
			<img id="4" class="img-responsive" src="" />
			<img id="5" class="img-responsive" src="" />
			<img id="6" class="img-responsive" src="" />
			<img id="7" class="img-responsive" src="" />
			<img id="8" class="img-responsive" src="" />
			<img id="9" class="img-responsive" src="" />
			<img id="10" class="img-responsive" src="" />
	<hr />
	<div class="row">
		<div class="col-xs-12 col-sm-4">
			<label>Image Display</label>
			<select id="imgDisplay" class="form-control">
				<option value="cover" default>cover</option>
				<option value="contain">contain</option>
		<div class="col-xs-12 col-sm-4">
			<select id="imgScroll" class="form-control">
				<option value="yes" default>Yes</option>
				<option value="no">No</option>
		<div class="col-xs-12 col-sm-4">
			<input type="range" min="200" max="1200" value="700" class="slider form-control" id="imgScale">

Step 2 – Add CSS

We use some external CSS link to this code. No need to worry about this, copy and paste below code between <head></head> tag.

<link href='' rel='stylesheet' type='text/css'>

Copy and paste below code in your HTML editor between <style></style> tag.

body {
  width: 100vw;
  height: 100vh;
  margin: 2% auto;
  background-color: #111;

label {
  color: #5d5dff;

#gallery {
  color: white;

#gallery-box {
  display: block;
  position: relative;
  max-height: 400px;
  width: 100%;
  overflow: scroll;
  width: 100%;

#gallery-box::-webkit-scrollbar {
  width: 10px;
  height: 10px;

#gallery-box::-webkit-scrollbar-track {
  background: #e5e5e5;

#gallery-box::-webkit-scrollbar-thumb {
  background: #5d5dff;

#gallery-box::-webkit-scrollbar-thumb:hover {
  background: #7d7dff;

#gallery-count {
  display: inline-block;
  position: absolute;
  top: 0;
  right: 0;
  padding: 15px;
  background-color: rgba(0, 0, 0, 0.8);
  color: #fff;
  height: 50px;
  text-decoration: none;

#gallery-img {
  display: -webkit-box;
  display: flex;
  min-height: 400px;
  min-width: 600px;
  height: auto;
  background: #e5e5e5;
  text-align: center;
  background-image: url("");
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  -webkit-transition: 0.3s ease-in-out;
  transition: 0.3s ease-in-out;

.gallery-thumbnails {
  display: -webkit-box;
  display: flex;
  height: auto;
  overflow: hidden;
  width: 100%;
  background: rgba(255, 255, 255, 0.1);
  border-top: 2px solid white;

.gallery-thumbnails img {
  float: left;
  width: 10%;
  cursor: pointer;
  padding: 0;
  -webkit-filter: grayscale(1);
          filter: grayscale(1);
  min-height: 25px;

.gallery-thumbnails img:hover {
  -webkit-filter: none !important;
          filter: none !important;

Step 2 – Add JavaScript

We use some external JavaScript link to this code. No need to worry about this, copy and paste below code between <head></head> tag.

 <script src=""></script> 
  <script src="">

Copy and paste below code in your HTML editor between <script></script> tag.

<script $(document).ready(function () {
	// Change image on selection
	$("#gallery img").click(function () {
		// Get current image source
		var image = $(this).attr("src");
		// Apply grayscale to thumbnails except selected
		$("#gallery").find("img").css("filter", "grayscale(1)");
		$(this).css("filter", "none");
		// Change image
		$("#gallery-img").css("background-image", "url(" + image + ")");
		// Apply link to image
		$("#gallery-link").attr("href", image);
		// Use id for count

	// Get total number of images
	var gallerySize = $(".gallery-thumbnails img").length;

	var display = $("#imgDisplay");
	var scroll = $("#imgScroll");
	var scale = $("#imgScale");

	// Image display
	display.change(function () {
		if (display.val() === "contain") {
			$("#gallery-img").css("background-size", "contain");
		} else {
			$("#gallery-img").css("background-size", "cover");

	// Scroll
	scroll.change(function () {
		if (scroll.val() === "yes") {
			$("#gallery-box").css("overflow", "scroll");
		} else {
			$("#gallery-box").css("overflow", "hidden");

	// Scale
	var changeScale = scale.change(function () {
		$("#gallery-img").css("background-size", scale.val() + "px");


At the end we will have something like this. You can change fonts, colors, backgrounds and all things that you want.Enjoy it.

Responsive Image Gallery

Video Tutorial

Please watch this video to better understand this tutorial and don’t forget to subscribe to our channel.

Help others to find out about this article on Social Media sites. If you have any doubt or any problem, don’t hesitate to contact us. Thereafter we will be able to help you and also make sure you bookmark our site on your browser.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button