:active-view-transition

Baseline 2025
Newly available

Since October 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

:active-view-transitionlớp giả CSS khớp với phần tử gốc của tài liệu khi một hiệu ứng chuyển cảnh view đang diễn ra (active) và ngừng khớp khi hiệu ứng chuyển cảnh hoàn tất.

Cú pháp

css
:root:active-view-transition ... {
  /* ... */
}

Ví dụ

Tạo kiểu cho hiệu ứng chuyển cảnh view đang hoạt động

Ví dụ này mở rộng ví dụ chuyển cảnh view cơ bản trên trang startViewTransition.

html
<main>
  <section class="color">
    <h2>Color is changing!</h2>
  </section>
  <button id="change-color">Change Color</button>
</main>

Phần tử <h2> ban đầu có kiểu display: none, và được ghi đè bằng lớp giả :active-view-transition để đặt kiểu <h2> thành display: block. Nút được ẩn bằng visibility: hidden khi hiệu ứng chuyển cảnh view đang diễn ra:

css
h2 {
  display: none;
  color: white;
}
:root:active-view-transition h2 {
  display: block;
}
:root:active-view-transition button {
  visibility: hidden;
}

Thông số kỹ thuật

Specification
CSS View Transitions Module Level 2
# the-active-view-transition-pseudo

Khả năng tương thích trình duyệt

Xem thêm