As developers, for years we've been forced to use massive JavaScript libraries to achieve fluid transitions and responsive designs. Well, in 2026, that's over! 🛑 Browsers have become incredibly powerful. Today, we're diving into two game-changing technologies that will completely transform your workflow: View Transitions and Container Queries. 🛠️
View Transitions: Seamless Swaps, Effortlessly ✨
Ever wondered how mobile apps achieve that buttery-smooth transition where an image seems to "fly" from one screen to another? With the View Transitions API, plain HTML/JS can now do it too! 🪄
💻 The Code You Need:
Instead of just replacing content with inner HTML, you'll use this native method:
function changePage(newContent) {
// 🔍 Check if the browser supports the API
if (!document.startViewTransition) {
document.querySelector('#app').innerHTML = newContent;
return;
}
// 🪄 The magic happens here
document.startViewTransition(() => {
document.querySelector('#app').innerHTML = newContent;
});
}
In your CSS, simply define the duration:
::view-transition-old(root),
::view-transition-new(root) {
animation-duration: 0.4s;
animation-timing-function: ease-in-out;
}
Container Queries: Farewell, Media Queries! 👋
Media Queries (@media) served us well, but they respond to the entire viewport size. In modern development, we want our components to be independent. 🧩
With Container Queries, your card adapts to the space it's placed in. If it's in a narrow sidebar, it automatically adjusts its layout regardless of the screen size.
🎨 CSS Example:
/* 1️⃣ Define the parent as a "container" */
.post-wrapper {
container-type: inline-size;
}
/* 2️⃣ Adapt based on the parent's width */
@container (min-width: 500px) {
.post-card {
display: grid;
grid-template-columns: 200px 1fr;
gap: 20px;
background: #161b22;
}
}
Why Should You Care? ⚡
- Speed: Less JavaScript means lightning-fast page loads. 💨
- Better UX: Pages feel like native apps, not static documents. 📱
- Modularity: Reuse components anywhere, and they'll always look correct. 🏗️
🙌 Did you enjoy this post?
If you like my blog and found this code helpful, please share it with your friends or leave a comment! 💬 Every bit of support helps me keep creating content about HTML, CSS, and JS. 🚀
👨💻 Stay tuned to Dervic Blog for more web development insights!✨
If you enjoyed this article, you may also like Dervic Blog.
Comments (0)