-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
CSS Basics
CSS Styling Properties
CSS Box Model
CSS Margin
CSS Padding
CSS Borders
CSS Outline
CSS Height/Width
CSS Max-width
CSS Display
CSS Position
CSS Z-index
CSS Overflow
CSS Float
CSS Inline-block
CSS Align
CSS Box Sizing
CSS Text
CSS Fonts
CSS Icons
CSS Text Effects
CSS Web Fonts
CSS Colors
CSS Backgrounds
CSS Color Keywords
CSS Gradients
CSS Shadows
CSS Links
CSS Lists
CSS Tables
CSS Advanced Selectors & Features
CSS Combinators
CSS Pseudo-classes
CSS Pseudo-elements
CSS Attribute Selectors
CSS Specificity
CSS !important
CSS Units
CSS Variables
CSS @property
CSS Math Functions
CSS Media and Image Styling
CSS Image Styling
CSS Image Centering
CSS Image Filters
CSS Image Shapes
CSS object-fit
CSS object-position
CSS Masking
CSS Layout Techniques
CSS Website Layout
CSS Navigation Bar
CSS Dropdowns
CSS Image Gallery
CSS Counters
CSS Pagination
CSS Multiple Columns
CSS User Interface
CSS Flexbox
CSS Grid
CSS Responsive Design (RWD)
max-width
in CSS?The max-width
property in CSS defines the maximum width an element can grow to, preventing it from becoming too wide, especially on large screens.
It is commonly used for responsive layouts.
element {
max-width: 600px;
}
This means: the element can grow up to 600px
, but no more.
max-width
px
– pixels (fixed size)
%
– relative to parent element
em
, rem
– relative to font size
vw
– relative to viewport width
max-width
)By default, block-level elements like <div>
stretch to 100% of their parent’s width.
Setting max-width
can help limit this behavior:
.container {
width: 100%;
max-width: 1200px;
margin: 0 auto;
}
✅ This creates a responsive, centered layout.
max-width
vs width
Property | Behavior |
---|---|
width |
Fixed width |
max-width |
Maximum limit; can shrink below |
min-width |
Minimum limit; cannot go below |
img {
max-width: 100%;
height: auto;
}
✅ Makes images resize within their containers and prevents overflow.
Q1. Set the max-width
of a <div>
to 800px.
Q2. Make sure a <section>
element doesn’t grow beyond 90% of the page width.
Q3. Set width: 100%
and max-width: 1000px
to create a responsive container.
Q4. Limit an image to a maximum width of 100% of its container.
Q5. Prevent a button from exceeding 200px in width.
Q6. Apply max-width: 500px
using a class .content-box
.
Q7. Write a media query that applies max-width: 700px
on screens wider than 768px.
Q8. Use max-width
in a flex container to keep items from stretching too far.
Q9. Write a rule to limit the maximum width of a form to 600px.
Q10. Use inline CSS to set max-width of a div to 400px.
CSS Basics
CSS Styling Properties
CSS Box Model
CSS Margin
CSS Padding
CSS Borders
CSS Outline
CSS Height/Width
CSS Max-width
CSS Display
CSS Position
CSS Z-index
CSS Overflow
CSS Float
CSS Inline-block
CSS Align
CSS Box Sizing
CSS Text
CSS Fonts
CSS Icons
CSS Text Effects
CSS Web Fonts
CSS Colors
CSS Backgrounds
CSS Color Keywords
CSS Gradients
CSS Shadows
CSS Links
CSS Lists
CSS Tables
CSS Advanced Selectors & Features
CSS Combinators
CSS Pseudo-classes
CSS Pseudo-elements
CSS Attribute Selectors
CSS Specificity
CSS !important
CSS Units
CSS Variables
CSS @property
CSS Math Functions
CSS Media and Image Styling
CSS Image Styling
CSS Image Centering
CSS Image Filters
CSS Image Shapes
CSS object-fit
CSS object-position
CSS Masking
CSS Layout Techniques
CSS Website Layout
CSS Navigation Bar
CSS Dropdowns
CSS Image Gallery
CSS Counters
CSS Pagination
CSS Multiple Columns
CSS User Interface
CSS Flexbox
CSS Grid
CSS Responsive Design (RWD)