CSS: min-width max-width, min-height max-height
min-width max-width, min-height max-height
min-widthmax-widthmin-heightmax-height
These are CSS properties that specify the absolute lower bound and upper bound width and neight for an element.
If you want to make sure a box size never changes in any condition, (even inside flex/grid containers or with lots of content), give them the same value with fixed unit, such as px.
.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.
CSS. width related.
- CSS: Layout. Index
- CSS: Font based units: rem rcap rch rex ric
- CSS: Viewport based units: vw vh vmin vmax vi vb
- CSS: Percentage value
- CSS: @container query
- CSS: min-width max-width, min-height max-height
- CSS: min-content, max-content
- CSS: fit-content (shrink wrap)
- CSS: clamp()
- CSS: min() max()
- CSS: calc()