CSS: min-width max-width, min-height max-height
min-width max-width, min-height max-height
min-widthmax-widthmin-heightmax-height
These specify min and max width, and height, for an element.
If you want to make sure a box size never changes in any condition, give them the same value with fixed unit, such as px. It works inside flex/grid containers too.
.fixed-box { width: 300px; height: 200px; min-width: 300px; /* prevent shrinking */ max-width: 300px; /* prevent growing */ min-height: 200px; max-height: 200px; /* Recommended additions */ box-sizing: border-box; /* makes padding/border part of the size */ overflow: auto; /* handles content that overflows */ }
Browser support
supported by all major browsers since 2016.