Learn how to create Expanding Card with just simple HTML, CSS and JavaScript.

Checkout the codes:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" href="style.css" />
<title>Expanding Cards</title>
</head>
<body>
<div class="container">
<div
class="panel active"
style="background-image: url('images/amazing_landscape-wallpaper-1440x900.jpg')"
>
<h3>Explore the Wild</h3>
</div>
<div
class="panel"
style="background-image: url('images/lake_shore-wallpaper-1440x900.jpg')"
>
<h3>Gone with the Wind</h3>
</div>
<div
class="panel"
style="background-image: url('images/love_11-wallpaper-1440x900.jpg')"
>
<h3>Love is Magical</h3>
</div>
<div
class="panel"
style="background-image: url('images/mountain_lake_17-wallpaper-1440x900.jpg')"
>
<h3>Call of the Wild</h3>
</div>
<div
class="panel"
style="background-image: url('images/woman_red_umbrella_rain-wallpaper-1440x900.jpg')"
>
<h3>Red Umbrella</h3>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
@import url("https://fonts.googleapis.com/css2?family=Syne+Mono&display=swap");
* {
box-sizing: border-box;
}
body {
font-family: "Syne Mono", monospace;
margin: 0 auto;
display: flex;
flex-direction: column;
align-items: center;
height: 100vh;
overflow: hidden;
}
.container {
display: flex;
width: 90vw;
}
.panel {
background-position: center;
background-size: cover;
background-repeat: no-repeat;
border-radius: 50px;
color: #fff;
height: 80vh;
margin: 10px;
flex: 0.5;
position: relative;
-webkit-transition: all 700ms ease-in;
}
.panel h3 {
font-size: 24px;
left: 20px;
position: absolute;
bottom: 20px;
margin: 0;
opacity: 0;
}
.panel.active {
flex: 5;
}
.panel.active h3 {
opacity: 1;
transition: opacity 0.3s ease-in 0.4s;
}
const panel = document.querySelectorAll(".panel");
panel.forEach(panel => {
panel.addEventListener("click", () => {
removeActiveClasses();
panel.classList.add("active");
});
});
function removeActiveClasses() {
panel.forEach(panel => {
panel.classList.remove("active");
});
}
Make sure to include the path for your JavaScript file in you Index.html file.
Go ahead and try it yourself.