Can you explain the concept of CSS containment and its use cases?

Instruction: Describe what CSS containment is and how it can be used to improve web performance.

Context: This question tests the candidate's knowledge on CSS containment property, a modern CSS feature aimed at allowing developers to isolate a subtree of the document to improve rendering performance.

Updated

Official answer available

Read the opening below, then unlock the full answer and practical guidance.

contain allows the browser to rely on specific isolation guarantees. Each value changes behavior, so use the smallest containment contract the component can satisfy. It is not a generic “make this widget faster” switch.

<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS example</title> <style> .panel { width: 180px; border: 1px solid; margin: 1rem 0; } .layout { contain: layout; } .size { contain: size; } .paint { height: 50px; contain:...

Related Questions