Popular Hero Section Slider Using Html Css Js Simple Example

Popular Hero Section Slider Using Html Css Js Simple Example

Suraj (UI/UX Developer)
Jul 2024
HTML

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>Hero Slider for Websites Designs Using Html Css Js</title>

<link rel="stylesheet" href="css/style.css" />

<link rel="stylesheet" href="css/swiper-bundle.min.css" />

</head>

<body>

<section class="main swiper mySwiper">

<div class="wrapper swiper-wrapper">

<div class="slide swiper-slide">

<img src="images/5.jpeg" alt="" class="image" />

<div class="image-data">

<span class="text">Add Website Sub title one </span>

<h2>Popular & Best Hero Slider </h2>

<h2>Fully Mobile Responsive Designs</h2>

<h2>Using Html Css JavaScript</h2>

<a href="#" class="button">Read more</a>

</div>

</div>

<div class="slide swiper-slide">

<img src="images/6.jpeg" alt="" class="image" />

<div class="image-data">

<span class="text">Add Website Sub title one </span>

<h2>Popular Free Best Hero Slider Section</h2>

<h2>Fully Mobile Responsive Designs</h2>

<h2>Using Html Css JavaScript</h2>

<a href="#" class="button">Read more</a>

</div>

</div>

<div class="slide swiper-slide">

<img src="images/4.jpeg" alt="" class="image" />

<div class="image-data">

<span class="text">Add Website Sub title one </span>

<h2>Our & Best Hero Slider </h2>

<h2>Fully Mobile Responsive Designs</h2>

<h2>Using Html Css JavaScript</h2>

<a href="#" class="button">Read more</a>

</div>

</div>

</div>

<div class="swiper-button-next nav-btn"></div>

<div class="swiper-button-prev nav-btn"></div>

<div class="swiper-pagination"></div>

</section>

<script src="js/swiper-bundle.min.js"></script>

</body>

</html>

CSS

/* Google Fonts - Poppins */
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600&display=swap");

* {
 margin: 0;
 padding: 0;
 box-sizing: border-box;
 font-family: "Poppins", sans-serif;
}
.main {
 height: 100vh;
 width: 100%;
}
.wrapper,
.slide {
 position: relative;
 width: 100%;
 height: 100%;
}
.slide {
 overflow: hidden;
}
.slide::before {
 content: "";
 position: absolute;
 height: 100%;
 width: 100%;
 background-color: rgb(0 0 0 / 59%);
 z-index: 10;
}
.slide .image {
 height: 100%;
 width: 100%;
 object-fit: cover;
}
.slide .image-data {
 position: absolute;
 top: 50%;
 left: 50%;
 transform: translate(-50%, -50%);
 text-align: center;
 width: 100%;
 z-index: 100;
}
.image-data span.text {
 font-size: 20px;
 font-weight: 400;
  text-shadow: 2px 2px 1px black;
 color: #fff;
}
.image-data h2 {
 font-size: 50px;
 font-weight: 600;
     text-shadow: 2px 2px 1px black;
 color: #fff;
}
a.button {
 display: inline-block;
 padding: 10px 20px;
 border-radius: 20px 0px;
 color: #333;
 font-weight: 700;
 background: #fff;
 text-decoration: none;
 margin-top: 25px;
 transition: all 0.3s ease;
}
a.button:hover {
 color: #fff;
 background-color: #c87e4f;
}

/* swiper button css */
.nav-btn {
 height: 50px;
 width: 50px;
 border-radius: 50%;
 background: rgba(255, 255, 255, 0.3);
}
.nav-btn:hover {
 background: rgba(255, 255, 255, 0.4);
}
.swiper-button-next {
 right: 50px;
}
.swiper-button-prev {
 left: 50px;
}
.nav-btn::before,
.nav-btn::after {
 color: #ffffff;
}
 

JavaScript

<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css"><script src="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js"></script>

    <script>
     var swiper = new Swiper(".mySwiper", {
       slidesPerView: 1,
       loop: true,
       pagination: {
         el: ".swiper-pagination",
         clickable: true,
       },
       navigation: {
         nextEl: ".swiper-button-next",
         prevEl: ".swiper-button-prev",
       },
     });
   </script>