Shrinks to smallest possible (longest word/unbreakable content)
width: min-content;
max-content
Maximum width
Expands to fit all content without wrapping
width: max-content;
fit-content
Adaptive width
Uses max-content up to available space, then wraps
width: fit-content;
fit-content(limit)
Clamped adaptive
Like fit-content but with maximum limit
width: fit-content(300px);
stretch NEW
Fill available
Fills available space (replaces old -webkit-fill-available)
width: stretch;
Example: Intrinsic sizing keywords
/* min-content - smallest possible width */.min-width { width: min-content; /* Width = longest word or unbreakable content */}/* max-content - no wrapping */.max-width { width: max-content; /* Expands to fit all content on one line */}/* fit-content - smart adaptive */.fit-width { width: fit-content; /* Uses max-content if space available, otherwise wraps */ max-width: 100%; /* Prevent overflow */}/* fit-content with limit */.limited { width: fit-content(500px); /* Max 500px, shrinks if less space available */}/* Practical: button sizing */button { width: fit-content; /* Wraps text naturally */ min-width: 120px; /* Minimum size */}/* Stretch - fill available space */.stretch { width: stretch; /* Fills parent (like width: 100%) */}
Example: Practical intrinsic sizing patterns
/* Card with dynamic width based on content */.card { width: fit-content; min-width: 250px; max-width: 100%;}/* Table column sizing */th, td { width: max-content; /* Fit content without wrapping */}/* Navigation items */.nav-item { width: fit-content; /* Shrinks to content */ padding: 0.5rem 1rem;}/* Grid with intrinsic columns */.grid { display: grid; grid-template-columns: min-content /* Icon/image column - smallest possible */ 1fr /* Main content - fills space */ max-content; /* Action buttons - no wrap */}
/* OLD WAY - padding-top hack */.old-ratio { position: relative; width: 100%; padding-top: 56.25%; /* 16:9 ratio (9/16 = 0.5625) */}.old-ratio > * { position: absolute; top: 0; left: 0; width: 100%; height: 100%;}/* NEW WAY - aspect-ratio property */.new-ratio { width: 100%; aspect-ratio: 16 / 9; /* Much simpler! */}/* Combining with object-fit for images */.responsive-image { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; /* Fill without distortion */}
Note:aspect-ratio replaces the old padding-top hack. Works with any dimension - set width or height, the other is calculated. Respects min/max
constraints.
5. Object-fit and Object-position for Media
Value
Behavior
Aspect Ratio
Use Case
fill
Stretch to fill container (default)
Distorts to match
Rare - causes distortion
contain
Scale to fit within container
Preserved - shows all content
Product images, logos (no cropping)
cover
Scale to fill container
Preserved - may crop edges
Hero images, backgrounds, thumbnails
none
Original size, centered
Preserved - may overflow/gap
Icons, exact size display
scale-down
Smaller of none or contain
Preserved - never enlarges
Thumbnails, small images
Property
Syntax
Description
Example
object-position
x y
Position content within box
object-position: center top;
Keywords
top, right, bottom, left, center
Named positions
object-position: right bottom;
Percentages
0-100%
Relative positioning
object-position: 75% 50%;
Lengths
px, em, rem
Absolute offset from top-left
object-position: 20px 10px;
Example: object-fit values comparison
/* Common pattern: responsive images */.image-container { width: 300px; height: 200px;}/* cover - fills space, crops if needed */.hero-image { width: 100%; height: 100%; object-fit: cover; object-position: center; /* Focus on center */}/* contain - shows all, may have gaps */.product-image { width: 100%; height: 100%; object-fit: contain; object-position: center;}/* scale-down - never enlarges */.thumbnail { max-width: 150px; max-height: 150px; object-fit: scale-down;}/* none - original size */.icon { width: 48px; height: 48px; object-fit: none;}
Example: object-position for focal points
/* Focus on top of image (faces, important content) */.portrait { object-fit: cover; object-position: center top;}/* Focus on bottom */.landscape { object-fit: cover; object-position: center bottom;}/* Precise positioning with percentages */.off-center { object-fit: cover; object-position: 75% 25%; /* Right-upper focus */}/* Video element */video { width: 100%; height: 400px; object-fit: cover; object-position: center;}/* Profile pictures - always square, centered */.avatar img { width: 100%; height: 100%; object-fit: cover; object-position: center; border-radius: 50%;}
Note: Use cover for backgrounds/thumbnails (fills space), contain for logos/products (shows all). object-position controls focal
point when content is cropped.
Warning:overflow: hidden creates a new formatting
context which can affect layout (margin collapse, floats). Use overflow: auto for
scrollable containers.
Box Model Best Practices
Always use box-sizing: border-box globally
Use aspect-ratio for responsive media containers
Use object-fit: cover for hero images, contain for product images
Use overflow: auto for scrollable areas (not scroll)
Use fit-content for buttons and dynamic width elements