Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
CSS

Create Smooth Page Transitions with CSS View Transitions API (No JavaScript)

- 01.02.26 | 01.02.26 - ErcanOPAK

Page navigation feels jarring? The new CSS View Transitions API creates native app-like transitions without a single line of JavaScript.

The Basic Setup:

/* Enable view transitions for all navigations */
@view-transition {
  navigation: auto;
}

/* Customize the transition */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.3s;
  animation-timing-function: ease-in-out;
}

/* Fade effect */
::view-transition-old(root) {
  animation-name: fade-out;
}

::view-transition-new(root) {
  animation-name: fade-in;
}

@keyframes fade-out {
  to { opacity: 0; }
}

@keyframes fade-in {
  from { opacity: 0; }
}

How It Works:
When the user navigates to a new page:
1. Browser captures a screenshot of the current page
2. Loads the new page in the background
3. Captures a screenshot of the new page
4. Animates between the two screenshots

All this happens automatically with just the CSS above. No JavaScript event listeners, no DOM manipulation, no library dependencies.

Advanced – Element-Specific Transitions:

/* Tag specific elements to transition smoothly */
.product-image {
  view-transition-name: product-hero;
}

.price-badge {
  view-transition-name: price-info;
}

/* Animate them differently */
::view-transition-old(product-hero),
::view-transition-new(product-hero) {
  animation-duration: 0.5s;
  height: 100%;
  object-fit: cover;
}

::view-transition-old(price-info) {
  animation: slide-out-right 0.3s ease-out;
}

::view-transition-new(price-info) {
  animation: slide-in-left 0.3s ease-out;
}

@keyframes slide-out-right {
  to { transform: translateX(100%); }
}

@keyframes slide-in-left {
  from { transform: translateX(-100%); }
}

Real-World Example – E-Commerce Product Pages:

/* Product listing page */
.product-card img {
  view-transition-name: var(--product-id);
  /* Each product gets unique transition name */
}

/* Product detail page */
.hero-image {
  view-transition-name: var(--product-id);
  /* Same name = smooth morph from thumbnail to full size */
}

When users click a product thumbnail, it smoothly expands into the hero image on the detail page. No JavaScript libraries, no complex state management.

Why This Matters:
Before View Transitions API:
• React Router: +40KB bundle
• Framer Motion: +60KB bundle
• Custom JavaScript: 100+ lines of code
• Performance overhead from JS parsing and execution

With View Transitions API:
• 0KB JavaScript
• Native browser optimization
• Hardware-accelerated animations
• 20 lines of CSS

Browser Support (as of 2024):
✅ Chrome 111+
✅ Edge 111+
✅ Opera 97+
⚠️ Firefox: Behind flag
⚠️ Safari: In development

Graceful Degradation:

@supports (view-transition-name: none) {
  /* View Transitions supported */
  @view-transition { navigation: auto; }
}

@supports not (view-transition-name: none) {
  /* Fallback for unsupported browsers */
  * { transition: opacity 0.2s; }
}

In unsupported browsers, pages just load normally. No broken experience, no errors.

Related posts:

CSS: Fix a Hover Effect That Flickers Repeatedly Instead of Staying Stable

CSS: Fix a Hover Effect That Flickers Repeatedly Instead of Staying Stable

CSS: Master Font Sizing for Responsive Typography

CSS: Master Font Sizing for Responsive Typography

CSS: Create Neumorphism with Box Shadows

CSS: Create Neumorphism with Box Shadows

Views: 10

Post navigation

Fix Windows 11 Slow Boot by Cleaning Up Startup Items (PowerShell Method)
Use HTML Dialog Element for Accessible Modals (Forget JavaScript Libraries)

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (980)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (653)
  • Add Constraint to SQL Table to ensure email contains @ (609)
  • Average of all values in a column that are not zero in SQL (570)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (547)
  • Find numbers with more than two decimal places in SQL (475)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (980)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com