### HTML markup for independent widgets Source: https://www.w3.org/TR/css-contain-2 Example markup for a micropost social network page with many independent message articles. Used to illustrate applying contain: content or contain: strict to each article so the user agent can optimize rendering. ```html

Messages

Lol, check out this dog: images.example.com/jsK3jkl
I had a ham sandwich today. #goodtimes
I have political opinions that you need to hear!
…
``` -------------------------------- ### content-visibility: auto example Source: https://www.w3.org/TR/css-contain-2 Use content-visibility: auto to let the user-agent skip rendering of off-screen content. When the element is near the viewport, the user-agent paints it; when it moves away, it stops painting and skips as much rendering work as possible. ```html
... some content goes here ...
``` -------------------------------- ### content-visibility: hidden example Source: https://www.w3.org/TR/css-contain-2 Use content-visibility: hidden to skip rendering regardless of viewport intersection. The only way to paint the contents is via script updating the value to remove content-visibility or change its value. The user-agent should skip as much rendering work as possible. ```html
... some content goes here ...
``` -------------------------------- ### Style containment with counter-increment Source: https://www.w3.org/TR/css-contain-2 Shows how style containment scopes counter-increment to the subtree. The first use of the counter inside the subtree acts as if it were set to 0 at the scoping element, so the displayed output is "1 1.2". ```html
``` ```css div { contain: style; counter-increment: n; } div::before, div::after { content: counters(n, '.') " "; } div::after { counter-increment: n 2; } ``` -------------------------------- ### Size containment with aspect-ratio Source: https://www.w3.org/TR/css-contain-2 CSS rule and HTML markup showing that with size containment, the image is sized to 100px by 100px because the aspect-ratio property is honored. The width is set to 100px and the aspect-ratio to 1/1, while contain: size suppresses the natural aspect ratio but allows the preferred aspect ratio from aspect-ratio to take effect. ```css img { width: 100px; aspect-ratio: 1/1; contain: size; } ``` ```html ``` -------------------------------- ### Forcing rendering work with getBoundingClientRect() Source: https://www.w3.org/TR/css-contain-2 Shows that accessing a layout value (getBoundingClientRect()) inside a content-visibility: hidden element forces rendering work, including layout, if the user-agent previously avoided it. The result is a rect at (11, 22) with size 100x200. Repeated calls to the same layout value should not cause additional rendering work. ```html
... some other content goes here ...
``` -------------------------------- ### ContentVisibilityAutoStateChangedEvent Source: https://www.w3.org/TR/css-contain-2 The ContentVisibilityAutoStateChangedEvent interface is an event that fires when the content-visibility auto state changes for an element. It includes a constructor and a readonly attribute indicating whether the content is skipped. ```APIDOC ## ContentVisibilityAutoStateChangedEvent ### Description Fires when the content-visibility auto state changes for an element. ### Constructor `ContentVisibilityAutoStateChangedEvent(type, eventInitDict)` ### Parameters - **type** (DOMString) - Required - The event type. - **eventInitDict** (ContentVisibilityAutoStateChangedEventInit) - Optional - Initialization dictionary. ### Attributes - **skipped** (boolean) - Read-only - Indicates whether the content is skipped. ### Dictionary `ContentVisibilityAutoStateChangedEventInit` - **skipped** (boolean) - Optional - Default `false` - Indicates whether the content is skipped. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.