CSS contain Property

Beginner
5 examples
Updated: Nov 2026

Definition and Usage

The contain property tells the browser that an element's subtree is independent for layout, paint, or size. This can improve rendering performance for complex widgets.

CSS Syntax

syntax.css
.widget {
  contain: layout paint;
}

Property Values

ValueEffectTry it
noneNo containmentTry it
layoutInternal layout does not affect outsideTry it
paintDescendants do not paint outsideTry it
sizeSize does not depend on descendantsTry it
contentShorthand for layout paint styleTry it

CSS Examples

Basic use

example.css
.widget {
  contain: layout paint;
}
Try It Yourself

Browser Support

contain is a CSS property.

✓ CSS

contain

Check support for your audience.

92% Modern browsers
Google Chrome Recent
Full support
Mozilla Firefox Recent
Full support
Apple Safari Recent
Full support
Microsoft Edge Recent
Full support
contain Modern support

Bottom line: Prefer progressive enhancement when support varies.

Frequently Asked Questions

The contain property tells the browser that an element's subtree is independent for layout, paint, or size. This can improve rendering performance for complex widgets.
Use it with progressive enhancement and check current browsers for edge cases.
Read the definition, try the first example, then compare related properties.
Sometimes. Prefer modern properties when browser support meets your audience.
Open the Try it demos and change one value at a time.

Next: container-name

Continue with container-name.

container-name →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful