How can I lazy-load images inside cards with a blur-up effect using utilities?
Asked on Sep 07, 2025
1 Answer
To lazy-load images with a blur-up effect in Bootstrap 5, you can use the `loading="lazy"` attribute along with CSS for the blur effect. This approach enhances performance by loading images only when they are about to enter the viewport.
<!-- BEGIN COPY / PASTE -->
<div class="card" style="width: 18rem;">
<img src="low-res-image.jpg" class="card-img-top blur" alt="..." loading="lazy">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
<style>
.blur {
filter: blur(10px);
transition: filter 0.3s;
}
.blur-loaded {
filter: blur(0);
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function () {
const img = document.querySelector('.card-img-top');
img.onload = () => img.classList.add('blur-loaded');
});
</script>
<!-- END COPY / PASTE -->
Additional Comment:
✅ Answered with Bootstrap 5 best practices.- Use the `loading="lazy"` attribute to defer loading of off-screen images.
- The `.blur` class applies an initial blur effect to the image.
- The `.blur-loaded` class removes the blur once the image is fully loaded.
- The JavaScript snippet listens for the image's `onload` event to transition the blur effect.