Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • jQuery
  • AngularJS
  • ReactJS
  • Next.js
  • React Native
  • NodeJS
  • Express.js
  • MongoDB
  • MERN Stack
  • PHP
  • WordPress
  • Bootstrap
  • Tailwind
  • CSS Frameworks
  • JS Frameworks
  • Web Development
Open In App
Next Article:
How to create a Spotlight Effect using HTML and CSS ?
Next article icon

How to make photo sliding effect using HTML and CSS ?

Last Updated : 30 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

It is an easy and amazing animation effect created with HTML and CSS, where the photos are moving horizontally one by one like a roller. When the mouse pointer comes upon the photo then the specific photo stops moving.

Approach: The basic idea of these animation comes from the hover effect of CSS animation. Let us see how the code works.

HTML code: The photos will be moving in a circular ring using HTML. To create the animation, we have taken a “div” and a section to maintain the area of the photos properly and the class name is used in the CSS code. We used HTML figure and img tag for the photos which will be shown in the page.

HTML
<!DOCTYPE html> <html>  <body>     <div class="addition">         <section class="slideshow">             <div class="content">                 <div class="content-carrousel">                     <figure class="shadow">                         <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20201105170558/geeks112.png">                     </figure>                     <figure class="shadow">                         <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20201105170611/geeks28.png">                     </figure>                     <figure class="shadow">                         <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20201105170619/geeks33.png">                     </figure>                     <figure class="shadow">                         <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20201105170627/geeks41.jpg">                     </figure>                     <figure class="shadow">                         <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20201105170635/geeks51.jpg">                     </figure>                     <figure class="shadow">                         <img src= "https://media.geeksforgeeks.org/wp-contentuploads/20201105170644/geeks61.jpg">                     </figure>                 </div>             </div>         </section>     </div> </body>  </html> 

CSS Code: Let us talk about the CSS part of the code. Some basic attributes are used like margin, padding, position, float, border, animation, etc which will help the photos giving them the right position. It helps to rotate the photos in 2D. First it rotates around its own axis. Then the whole “div” rotates around its axis.

To create this animation, figure:nth-child(“no. of child”) property is used. The transform:rotateY(amount of deg) and translateZ(–px) are the two attributes of CSS which helps to rotate the object.

CSS
<style>     body {         background-color: #000000;     }      .addition {         margin-left: 35%;         margin-top: 10%;     }      .slideshow {         position: centre;         margin: 0 auto;         padding-top: 50px;         height: 250px;         background-color: rgb(10, 10, 10);         box-sizing: border-box;     }      .content {         margin: auto;         width: 190px;         perspective: 1000px;         position: relative;         padding-top 80px;     }      .content-carrousel {         padding-left: 40px;          /* This helps to rotate the          photo div with respest to          axis of an another circle */         width: 100%;         position: absolute;         float: right;         animation: rotar 15s infinite linear;         transform-style: preserve-3d;     }      .content-carrousel:hover {          /* This is a hover effect.          when the mouse will reach          on the photo, the photo          will stop moving */         animation-play-state: paused;         cursor: pointer;     }      .content-carrousel figure {          /* width of the full image div*/         width: 100%;          /* height of the full image div*/         height: 120px;         border: 1px solid #4d444d;         overflow: hidden;         position: absolute;     }      /* The calculation part starts for the angle.     first, take the number of photos and then divide      by 360 and write it in the position of degree */      .content-carrousel figure:nth-child(1) {         transform: rotateY(0deg) translateZ(300px);     }      .content-carrousel figure:nth-child(2) {         transform: rotateY(60deg) translateZ(300px);     }      .content-carrousel figure:nth-child(3) {         transform: rotateY(120deg) translateZ(300px);     }      .content-carrousel figure:nth-child(4) {         transform: rotateY(180deg) translateZ(300px);     }      .content-carrousel figure:nth-child(5) {         transform: rotateY(240deg) translateZ(300px);     }      .content-carrousel figure:nth-child(6) {         transform: rotateY(300deg) translateZ(300px);     }      .content-carrousel figure:nth-child(7) {         transform: rotateY(360deg) translateZ(300px);     }      .slideshow {         position: absolute;         box-shadow: 0px 0pz 20px 0px #000;         border-radius: 2px;     }      .content-carrousel img {         image-rendering: auto;          /* The photo will move          with this velocity */         transition: all 300ms;                  /* width of the photo */         width: 100%;                  /* height of the photo */         height: 100%;     }      .content-carrousel img:hover {         transform: scale(1.2);         transition: all 300ms;     }      @keyframes rotar {         from {             transform: rotateY(0deg);         }          to {             transform: rotateY(360deg);         }     } </style> 

Final code: In this section, we will combine the above two sections (HTML and CSS) of code.

HTML
<!DOCTYPE html> <html>  <head>     <style>         body {             background-color: #000000;         }          .addition {             margin-left: 35%;             margin-top: 10%;         }          .slideshow {             position: centre;             margin: 0 auto;             padding-top: 50px;             height: 250px;             background-color: rgb(10, 10, 10);             box-sizing: border-box;         }          .content {             margin: auto;             width: 190px;             perspective: 1000px;             position: relative;             padding-top 80px;         }          .content-carrousel {             padding-left: 40px;             width: 100%;             position: absolute;             float: right;             animation: rotar 15s infinite linear;             transform-style: preserve-3d;         }          .content-carrousel:hover {             animation-play-state: paused;             cursor: pointer;         }          .content-carrousel figure {             width: 100%;             height: 120px;             border: 1px solid #4d444d;             overflow: hidden;             position: absolute;         }          .content-carrousel figure:nth-child(1) {             transform: rotateY(0deg) translateZ(300px);         }          .content-carrousel figure:nth-child(2) {             transform: rotateY(60deg) translateZ(300px);         }          .content-carrousel figure:nth-child(3) {             transform: rotateY(120deg) translateZ(300px);         }          .content-carrousel figure:nth-child(4) {             transform: rotateY(180deg) translateZ(300px);         }          .content-carrousel figure:nth-child(5) {             transform: rotateY(240deg) translateZ(300px);         }          .content-carrousel figure:nth-child(6) {             transform: rotateY(300deg) translateZ(300px);         }          .content-carrousel figure:nth-child(7) {             transform: rotateY(360deg) translateZ(300px);         }          .slideshow {             position: absolute;             box-shadow: 0px 0pz 20px 0px #000;             border-radius: 2px;         }          .content-carrousel img {             image-rendering: auto;             transition: all 300ms;             width: 100%;             height: 100%;         }          .content-carrousel img:hover {             transform: scale(1.2);             transition: all 300ms;         }          @keyframes rotar {             from {                 transform: rotateY(0deg);             }              to {                 transform: rotateY(360deg);             }         }     </style>  </head>  <body>     <div class="addition">         <section class="slideshow">             <div class="content">                 <div class="content-carrousel">                     <figure class="shadow">                         <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20201105170558/geeks112.png">                     </figure>                     <figure class="shadow">                         <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20201105170611/geeks28.png">                     </figure>                     <figure class="shadow">                         <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20201105170619/geeks33.png">                     </figure>                     <figure class="shadow">                         <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20201105170627/geeks41.jpg">                     </figure>                     <figure class="shadow">                         <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20201105170635/geeks51.jpg">                     </figure>                     <figure class="shadow">                         <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20201105170644/geeks61.jpg">                     </figure>                 </div>             </div>         </section>     </div> </body>  </html> 

Output:

https://media.geeksforgeeks.org/wp-content/uploads/20240725171745/uiop.mp4


Next Article
How to create a Spotlight Effect using HTML and CSS ?
author
chalti
Improve
Article Tags :
  • Web Technologies
  • Web Templates

Similar Reads

  • How to create a Spotlight Effect using HTML and CSS ?
    In this article, we are going to create a spotlight effect over the image when we hover over it. This is mainly based on HTML, CSS and JavaScript. The below steps have to be followed to create this effect. HTML Section: In this section, we will create a container elements for the background image an
    4 min read
  • How to make Profile Card Hover Effect using CSS ?
    Almost all of us must have heard that 'the first impression is the last impression'. The profile card carries the most important details we should know about a person at the very first instant. A better impression attracts more traffic. So to engage more audience in a website it is very important to
    3 min read
  • How to create reflection effect using HTML and CSS ?
    The reflection effect is one of the coolest effects that one can use in his/her website. It is a type of informal effect so it is highly recommended not to use it any professional project. You can use it in your personal projects and maybe your portfolio to show your creativity. In this effect, we t
    3 min read
  • How to create Neumorphism Effect using HTML and CSS ?
    Neumorphism (neomorphism) is a modern way of styling web-elements of any web-page and providing a 3D effect. This animation effect can be easily generated by using HTML and CSS. Box-shadow property of CSS can be used to implemented Neumorphism. It is used to add a dark shadow to one side and a light
    2 min read
  • How to Make a Glass/Blur Effect Overlay using HTML and CSS?
    To give a background blur effect on an overlay, the CSS backdrop-filter: blur() property is used with ::before pseudo-element. The backdrop-filter: blur() property gives the blur effect on the box or any element where it is desired and “before” is used to add the blurred background without applying
    3 min read
  • Apply Glowing Effect to the Image using HTML and CSS
    While surfing most of the websites you have seen some special effects which can be seen on various images while putting your cursor over them. So, in this article, we are going to implement the same. We can use such images as a card for our website.  In this article, you’re going to learn how to app
    2 min read
  • How to create windows loading effect using HTML and CSS ?
    In this article, we are going to create a window loading effect before the lock screen appears using HTML and CSS.  Glimpse of the Windows Loading Effect: Approach: Create an HTML file that contains HTML div in which we are giving the loader effect.Then we create 5 span elements which are used for c
    4 min read
  • How to create image slider using HTML CSS and JavaScript ?
    An image slide, or slideshow, is a dynamic display of images that automatically transitions from one to the next, often with animations. To create an image slide, use HTML to structure the images, CSS for styling and animations, and JavaScript to control the timing and transitions between images. Ap
    3 min read
  • How to spin text on mouse hover using HTML and CSS?
    The spinning of text on mouse hover is known as the Spin Effect or the Rotation Effect. In this effect, each alphabet of the word is rotated along with any one of the axes (preferably Y-axis). Each word is wrapped inside in <li> tag and then using CSS:hover Selector selector we will rotate eac
    3 min read
  • How to create swinging Image Hanger using HTML and CSS ?
    In this article, we will learn how to create a type of Image Hanger that undergoes a swinging motion using HTML and CSS. This can be used to add interactivity to the page or highlight an image to draw attention. Approach: We will first create an HTML file in which we are going to add an image for ou
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences