Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS How to Make a Website Responsive Web Design and Testing Adding Breakpoints for Devices

Rob Harding
Rob Harding
4,128 Points

Min/max-width vs width

Whats the difference between min/max-width vs width?

3 Answers

Oğulcan Girginc
Oğulcan Girginc
24,848 Points

Hi,

Mozilla Developer Network's (MDN) definitions are quite good.

width:

The width CSS property specifies the width of the content area of an element. The content area is inside the padding, border, and margin of the element.

min-width:

The min-width CSS property is used to set the minimum width of a given element. It prevents the used value of the width property from becoming smaller than the value specified for min-width.

max-width:

The max-width CSS property is used to set the maximum width of a given element. It prevents the used value of the width property from becoming larger than the value specified for max-width.

Yulia Markina
Yulia Markina
12,616 Points

Hi Rob, I can only add to Ogulcan's answer that min/max-width properties are essential when you're building a responsive website. It gives you control on displaying your content properly and predictable.

width {50px; } - no matter what the width of the object is 50px

min-width {50px; } - the object HAS to be at least 50px.

max-width {50px; } - the absolute widest the object can be is 50px.

Basically said just exactly what Ogulcan posted, just summarized :)