--- layout: "@/layouts/ExplainerLayout.astro" demoTitle: "View Transition Example: Clipped Overflow" demoText: "This example shows how to prevent morphing view transitions between two different images from growing beyond the original size of the old and new images." title: "How does it work?" --- The [previous example](/demo/BasicIM2/) demonstrated that the default styling for view transitions can force images to grow larger than the original old or new image dimensions before they fade out. ### Preventing Image Overflow Preventing the old and new images from overflowing the group outline is straightforward. The group pseudo-element is the parent of the image pair, which in turn is the parent of the image pseudo-elements. Simply setting the overflow property on the group pseudo-element will take care of it. ```css ins={1-3} ::view-transition-group(img) { overflow: clip; } ``` Now the images will be cut off when they extend beyond the boundaries of the transition group. Admittedly, cutting the face in half isn't visually appealing. ### Further Improvement: Prefer Height Over Width In this example it looks better when we also change [the default behavior of morph transitions](/basics/default-animations/#how-the-boxes-morph) from all images being _full group width_ to _full group height_. Now, the landscape image grows in from the left, creating a nice reveal effect. Adding `right: 0` keeps the face aligned with the right edge as it fades. ```css ins={1-6} ::view-transition-old(img), ::view-transition-new(img) { block-size: 100%; inline-size: auto; right: 0; } ``` ### More Options There are more options if you want to tweak the standard morph behavior. Here are some of the knobs you might want to turn: * inline-size and block-size, width and height: see above * z-index: The view transition API places the new image above the old one. You can change this by assigning the old image an appropriate z-index value. * opacity: As an alternative to the default cross-fade, you could only fade-out the upper image. * animation-name: if you don't need the fade, or want to define your own `mix-blend-mode` value you can set the `animation-name` to `none` * animation: if you want a different fade or even a different effect like shrinking or rotating * mix-blend-mode: when you canceled the default animation * object-fit: see [next example](/demo/BasicIM4/) * padding, borders, transforms,… ## Inspection Chamber Insights Here are the detailed pictures as seen with the inspection chamber.