If you are looking to spice up your UI with smooth animations and dynamic interaction, this recipe will show you how to cook up an interactive Expandable Travel Blog Card.

With a simple click, the card dynamically resizes, repositioning its content and revealing a hidden grid of featured tour destinations.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Blog Card Tutorial</title>
<!-- External Stylesheet: Custom layout, positioning, transitions, and hover effects -->
<link rel="stylesheet" href="style.css" />
<!-- Font Awesome Icons: Used for visual icons (e.g., search icon on hover) -->
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css"
/>
<!-- Google Fonts Imports: Preloading and importing 'Kanit' and 'Roboto Condensed' typography -->
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Kanit:wght@300;400;500;600;700&family=Roboto+Condensed:wght@300;400;700&display=swap"
rel="stylesheet"
/>
</head>
<body>
<!-- Main Viewport Container:
Centers the blog card vertically and horizontally on the screen using Flexbox
and displays a custom green gradient background. -->
<div class="container">
<!-- Blog Card Wrapper:
Serves as the main component container.
Toggling the '.change' class on this element via JavaScript dynamically alters
the size of the card and moves child elements smoothly using CSS transitions. -->
<div class="blog-card">
<!-- Featured Image Container:
Displays the main featured image. In default state, it acts as a left-side pop-out banner.
When '.change' is active, CSS scales it down (scale(0.6)) and shifts it to top-left. -->
<div class="blog-card-img">
<img src="images/danau-toba.png" alt="Featured Tour Image" />
</div>
<!-- Main Content Section:
Contains publication date, title, preview text, and the interactive toggle button.
When '.change' is active, this section scales slightly down and moves upward. -->
<div class="blog-card-content">
<h3>25 December 2026</h3>
<h1>Explore New Tours</h1>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Nisi itaque
fugit eum eos veniam eveniet!
</p>
<!-- Interactive Action Button:
Targeted by script.js. Clicking this triggers the class toggle on '.blog-card'
and alternates the nested span text between 'More' and 'Less'. -->
<button type="button" class="card-btn">Read <span>More</span></button>
</div>
<!-- Hidden Sub-Tours Showcase:
Positioned at the bottom of the expanded card. In default state, items are hidden
(opacity: 0, visibility: hidden). When '.change' is active, items become visible
with staggered transition delays (0.3s, 0.5s, 0.7s) to create a cascading effect. -->
<div class="blog-tours">
<!-- Sub-Tour Item 1 -->
<div class="blog-tours-item">
<div class="tour-img">
<img src="images/danau1.jpg" alt="Explore Tour 1" />
</div>
<span>Explore Tour 1</span>
<i class="fa-solid fa-magnifying-glass-location"></i>
</div>
<!-- Sub-Tour Item 2 -->
<div class="blog-tours-item">
<div class="tour-img">
<img src="images/danau3.jpg" alt="Explore Tour 2" />
</div>
<span>Explore Tour 2</span>
<i class="fa-solid fa-magnifying-glass-location"></i>
</div>
<!-- Sub-Tour Item 3 -->
<div class="blog-tours-item">
<div class="tour-img">
<img src="images/holbung.jpg" alt="Explore Tour 3" />
</div>
<span>Explore Tour 3</span>
<i class="fa-solid fa-magnifying-glass-location"></i>
</div>
</div>
</div>
</div>
<!-- External JavaScript: Handles click event listener and DOM manipulations -->
<script src="script.js"></script>
</body>
</html>/* ==========================================================================
GLOBAL RESET & BASE STYLES
========================================================================== */
/* Universal Reset: Standardizes margins, paddings, and box sizing across browsers */
* {
margin: 0;
padding: 0;
box-sizing: border-box; /* Ensures padding and border are included in element's total width/height */
}
/* Root Font Size Setup:
Setting font-size to 62.5% converts 1rem to 10px (assuming standard 16px browser default).
This makes responsive font sizing and rem calculations much easier to manage. */
html {
font-size: 62.5%;
}
/* ==========================================================================
2. CONTAINER & LAYOUT STRUCTURE
========================================================================== */
/* Main Fullscreen Container:
Uses Flexbox to center the blog card component perfectly both vertically and horizontally. */
.container {
width: 100%;
height: 100vh;
background: linear-gradient(145deg, #6db193 0%, #00814b 75%);
display: flex;
justify-content: center;
align-items: center;
}
/* Base Blog Card Component (Default / Collapsed State):
Establishes the base card dimensions, dark background, rounded corners, and shadow. */
.blog-card {
width: 45%;
height: 40%;
background-color: rgb(40, 40, 40);
border-radius: 2.5rem;
padding: 2.5rem;
box-shadow: 0 1.4rem 8rem rgba(40, 40, 40, 0.8);
position: relative; /* Provides positioning context for absolute child elements /
transition: all 0.5s; /* Smoothly animates size changes when .change class is toggled */
}
/* Expanded State for Blog Card:
Triggered by JavaScript via button click. Increases card size to accommodate sub-tours. */
.change.blog-card {
width: 55%;
height: 80%;
}
/* ==========================================================================
3. FEATURED IMAGE SECTION
========================================================================== */
/* Main Featured Image Wrapper (Default State):
Positioned partially overflowing out to the left side of the card using absolute positioning. */
.blog-card-img {
width: 30rem;
height: 30rem;
background: linear-gradient(145deg, #6db193 0%, #00814b 75%);
border-radius: 2rem;
position: absolute;
transform: translateY(-50%);
top: 50%;
left: -5rem;
transition: all 0.5s; /*Smooth transformation movement */
}
/* Featured Image Wrapper (Expanded State):
Shrinks the image using scale(0.6) and repositions it higher and further left. */
.change .blog-card-img {
transform: translateY(-50%) scale(0.6);
top: 15%;
left: -10rem;
}
/* Inner Image Styling */
.blog-card-img img {
width: 100%;
height: 100%;
object-fit: cover; /*Ensures image maintains aspect ratio without stretching */
border-radius: 2rem;
opacity: 0.5; /*Blends image with the underlying gradient wrapper */
}
/* ==========================================================================
4. CONTENT & TYPOGRAPHY
========================================================================== */
/* Text Content Wrapper (Default State):
Positions text and action button on the right side of the card. */
.blog-card-content {
position: absolute;
top: 15%;
left: 40%;
transition: all 0.5s;
}
/* Text Content Wrapper (Expanded State):
Moves text up and scales it down slightly to make room for the sub-tour gallery at the bottom. */
.change .blog-card-content {
top: 1%;
left: 15%;
transform: scale(0.8);
}
/* Date Headline */
.blog-card-content h3 {
font-family: "Roboto Condensed", sans-serif;
font-size: 2rem;
color: #999;
margin-bottom: 2rem;
}
/* Main Post Title */
.blog-card-content h1 {
font-family: "Kanit", sans-serif;
font-size: 3.5rem;
font-weight: 300;
color: #fff;
margin-bottom: 2rem;
}
/* Main Post Excerpt */
.blog-card-content p {
font-family: "Roboto Condensed", sans-serif;
font-size: 1.6rem;
color: #777;
width: 35rem;
margin-bottom: 3rem;
}
/* Interactive Action Button */
.blog-card-content button {
width: 16rem;
height: 4rem;
background: linear-gradient(145deg, #6db193 0%, #00814b 75%);
border: none;
color: #fff;
font-family: "Kanit", sans-serif;
font-size: 1.4rem;
text-transform: uppercase;
letter-spacing: 0.1rem;
border-radius: 2rem;
box-shadow: 0px 1rem 1rem rgba(0, 0, 0, 0.1);
cursor: pointer;
position: relative;
z-index: 100; /* Keeps button clickable above overlapping layout layers */
}
/* ==========================================================================
5. SUB-TOURS GALLERY (HIDDEN / EXPANDED SHOWCASE)
========================================================================== */
/* Sub-Tours Container:
Flex container placed at the bottom of the main card to hold featured sub-items. */
.blog-tours {
width: 100%;
display: flex;
justify-content: space-evenly;
position: absolute;
bottom: 6rem;
left: 0;
}
/* Individual Tour Item (Default State):
Hidden by default using opacity 0 and visibility hidden. */
.blog-tours-item {
box-shadow: 0 1rem 5rem rgba(0, 0, 0, 0.3);
border-radius: 1rem;
cursor: pointer;
position: relative;
opacity: 0;
visibility: hidden;
transition: all 0.2s;
}
/* Sub-Tours Reveal State:
Fades in items when .change class is active on the parent blog card. */
.change .blog-tours-item {
opacity: 1;
visibility: visible;
}
/* Staggered Entrance Animations:
Uses nth-child transition-delays to make cards pop in sequentially (cascading effect). */
.change .blog-tours-item:nth-child(1) {
transition: all 0.3s 0.3s; /* Delay: 0.3s */
}
.change .blog-tours-item:nth-child(2) {
transition: all 0.3s 0.5s; /* Delay: 0.5s */
}
.change .blog-tours-item:nth-child(3) {
transition: all 0.3s 0.7s; /* Delay: 0.7s */
}
/* Tour Thumbnail Card Background & Dimensions */
.tour-img {
width: 25rem;
height: 35rem;
background: linear-gradient(135deg, #6db193, #135627);
border-radius: 1rem;
}
/* Tour Thumbnail Image */
.tour-img img {
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 1rem;
opacity: 0.5;
transition: all 0.3s;
}
/* Vertical Rotated Text Label */
.blog-tours-item span {
position: absolute;
top: 50%;
left: -35%;
transform: translateY(-50%) rotateZ(-90deg); /* Rotates text vertically */
font-family: "Kanit", sans-serif;
font-size: 1.8rem;
text-transform: uppercase;
font-weight: 500;
letter-spacing: 0.8rem;
color: #fff;
}
/* Hover Action Icon (Search glass):
Hidden centered icon button on sub-tour card. */
.blog-tours-item i {
width: 6rem;
height: 6rem;
background-color: #01683d;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
font-size: 2.5rem;
color: #fff;
box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.1);
opacity: 0;
visibility: hidden;
}
/* ==========================================================================
6. HOVER EFFECTS
========================================================================== */
/* Dims image background further on hover */
.blog-tours-item:hover .tour-img img {
opacity: 0.05;
}
/* Reveals icon button smoothly on hover */
.blog-tours-item:hover i {
opacity: 1;
visibility: visible;
transition: all 0.3s 0.1s;
}// 1. DOM Element Selection
// Target the trigger button using its class name '.card-btn'
const button = document.querySelector(".card-btn");
// Target the main card container that holds all content and styling states
const blogCard = document.querySelector(".blog-card");
// 2. Event Listener Registration
// Attach a click event listener to the action button
button.addEventListener("click", () => {
blogCard.classList.toggle("change")
? (button.firstElementChild.textContent = "Less")
: (button.firstElementChild.textContent = "More");
});
🍳 How It Works (The Mechanics)
The magic behind this widget relies on class manipulation and CSS transitions:
- HTML Structure (
index.html):- A main wrapper (
.blog-card) hosts three primary sections: an overlay image wrapper (.blog-card-img), main textual content (.blog-card-content), and a hidden collection of items (.blog-tours).
- A main wrapper (
- Dynamic Toggle (
script.js):- A simple event listener is attached to the button (
.card-btn). - Clicking the button toggles the
.changeCSS class on the.blog-cardcontainer. It also swaps the button text between “More” and “Less” dynamically.
- A simple event listener is attached to the button (
- Smooth Transitions & Animations (
style.css):- Card Expansion: When
.changeis active,.blog-cardsmoothly scales its width and height. - Repositioning Layout: The main featured image shrinks (
scale(0.6)) and shifts position. The main textual content scales down slightly and repositions higher up to make room. - Staggered Reveal: The hidden sub-tour items (
.blog-tours-item) transition fromopacity: 0/visibility: hiddentoopacity: 1/visibility: visible. Each tour item utilizesnth-childtransition delays (0.3s,0.5s,0.7s) to create a slick cascading entrance effect.
- Card Expansion: When
📝 Key Customizable Variables & Styles
You can easily adapt this component to fit your own theme or brand by tweaking a few key CSS rules:
- Base Font Size:
html { font-size: 62.5%; }- Set so
1rem = 10pxfor easier responsive calculations across all dimensions.
- Set so
- Color Scheme & Gradients:
- Background gradient:
linear-gradient(145deg, #6db193 0%, #00814b 75%). Update these hex codes to match your brand palette. - Card base background:
background-color: rgb(40, 40, 40);. Modify this to change the dark theme tone.
- Background gradient:
- Card Dimensions:
- Default collapsed state:
width: 45%; height: 40%; - Expanded state (
.change.blog-card):width: 55%; height: 80%;
- Default collapsed state:
- Transition Timings:
- Main card & image movements:
transition: all 0.5s; - Staggered animation delays for tours (
.change .blog-tours-item:nth-child(...)):0.3s,0.5s,0.7s. Adjust these values to make the reveal faster or slower.
- Main card & image movements: