5. min width and max width - Responsive CSS Tutorial
Skills:
HTML & CSS80%
Key Takeaways
Use min-width and max-width for responsive CSS layouts
Full Transcript
we've got our layout working it's looking nice and Danny but it's getting too big now when we're getting up to these big sizes we don't want that to happen what we can do to do that is a new property we're not worrying about a new value right now we're thinking of a new property it works with the width and you probably saw the name of this lesson was minute and maxed with so we can actually set a width and a maximum or minimum width on an element as well so I'm gonna come and put that border back on here of two pixels solid magenta just so we can really see what's happening once again and let's come and give this we have a width of 90 percent but I'm also going to give it a max width of 600 pixels let's do 620 because that was our original design so we'll stick with the 620 that we originally had so now if we come and take a look at this and I refresh you're gonna see it's it's working at our small screen sizes our container is growing it's staying at 90 percent but at one point it's gonna get locked into play and right around here it stops growing because it's hit its maximum width and that means at large screen size is my text and line lengths aren't going to get too long but at small screens everything works nice and perfectly so we've sort of got the best of both worlds going now we can set a set value for the maximum size we want where we can keep a percentage to let it shrink when we want it to we can also set a min width so if I came on here and said min width I'm gonna set it pretty big of 500 pixels I wouldn't normally do this on a container but just for demonstration purposes we have our max so it's never gonna grow bigger than 620 and if I go this way it will never get smaller than 500 so when I hit 500 pixels you can see it stops and then I get side scrolling again which is why I wouldn't set a min width on my container but it does demonstrate how that property works so for now I'm gonna take this off I just wanted to introduce the idea of the minimum width in there but for the max width I will leave it on there when we're starting to think respond responsively for the container this is a really really common property to set on something to give a maximum size that size really depends on the layout and what you're building so I'm not gonna say that there's a specific max size that you should be going you will base it on the design that you're doing I will be going warned of some best practices for total lengths and total sizes in a little bit interestingly enough if you put your max width above your width it's still going to work because there are two different values max width and width are two different ones same with min width you can put them in any order in your CSS and it won't have an effect it's going to work no matter what so play around with them see if you can get used to it or figure it out if it's something that you're finding a little bit confusing don't stress about it too much we're gonna be using these a lot in the following projects that we're going to be building it's just going to help reinforce it the more we use it so you'll get the hang of it in no time
Original Description
🎓 View our courses: https://scrimba.com/links/all-courses
This tutorial is a part of "The Responsive Web Design Bootcamp" on Scrimba. Explore the full course here: https://rebrand.ly/responsivebootcamp_yt
When starting to think responsively, setting a max-width on an element can be very useful. Often we want a layout to be able to shrink down very small, but we want to limit the maximum size of elements to prevent line-lengths from getting to long and the layout from becoming awkward.
The properties
Both of these will prevent an element from either getting bigger or smaller than the sizes given, despite whatever might be set on the width property.
min-width - the minimum possible size an element can be
max-width - the maximum possible size an element can be
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Scrimba · Scrimba · 46 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
▶
47
48
49
50
51
52
53
54
55
56
57
58
59
60
CSS Grid Course: Learn the Basics in 3 Minutes
Scrimba
CSS Grid Course: Positioning Items
Scrimba
CSS Grid Course: Why Learn It And How It Compares To Bootstrap
Scrimba
CSS Grid Course: auto-fit & minmax
Scrimba
CSS Grid Course: Implicit Rows
Scrimba
CSS Grid Course: Fraction Units And Repeat
Scrimba
CSS Grid Course: Justify Items and Align Items
Scrimba
CSS Grid Course: An Awesome Image Grid
Scrimba
CSS Grid Course: Named Lines
Scrimba
CSS Grid Course: auto-fit vs auto-fill
Scrimba
CSS Grid Course: Justify Content and Align Content
Scrimba
CSS Grid Course: Template areas
Scrimba
27. Setting up the structure - Responsive CSS Tutorial
Scrimba
25. Making the navigation responsive - Responsive CSS Tutorial
Scrimba
36. Playing with the title's position and negative margins - Responsive CSS Tutorial
Scrimba
31. Starting the CSS for our page - Responsive CSS Tutorial
Scrimba
26. Taking a look at the rest of the project - Responsive CSS Tutorial
Scrimba
15. Spacing out the columns - Responsive CSS Tutorial
Scrimba
33. Starting to think mobile first - Responsive CSS Tutorial
Scrimba
22. Making our navigation look good - Responsive CSS Tutorial
Scrimba
37. Changing image size with object-fit - Responsive CSS Tutorial
Scrimba
44. Module Wrap up - Responsive CSS Tutorial
Scrimba
16. Controlling the vertical position of flex items - Responsive CSS Tutorial
Scrimba
39. Setting up the widgets and talking breakpoints - Responsive CSS Tutorial
Scrimba
42. Setting up the About Me page - Responsive CSS Tutorial
Scrimba
35. Changing the visual order with flexbox - Responsive CSS Tutorial
Scrimba
23. Adding the underline - Responsive CSS Tutorial
Scrimba
21. Using flexbox to start styling our navigation - Responsive CSS Tutorial
Scrimba
20. Creating a navigation - Responsive CSS Tutorial
Scrimba
40. Using a new pseudo class to wrap up the homepage - Responsive CSS Tutorial
Scrimba
43. Fixing up some loose ends - Responsive CSS Tutorial
Scrimba
32. Starting the layout. Looking at the big picture - Responsive CSS Tutorial
Scrimba
24. A more complicated navigation - Responsive CSS Tutorial
Scrimba
28. Feature article structure - Responsive CSS Tutorial
Scrimba
34. Styling the featured article - Responsive CSS Tutorial
Scrimba
18. Making layout responsive with flex direction - Responsive CSS Tutorial
Scrimba
19. flex direction explained - Responsive CSS Tutorial
Scrimba
41. Creating the recent posts page - Responsive CSS Tutorial
Scrimba
17. Media Query basics - Responsive CSS Tutorial
Scrimba
30. Home Page. HTML for the aside - Responsive CSS Tutorial
Scrimba
38. Styling recent articles for large screens - Responsive CSS Tutorial
Scrimba
29. The home page. HTML for the recent articles - Responsive CSS Tutorial
Scrimba
10. ems and rems an example - Responsive CSS Tutorial
Scrimba
1. Starting to think responsively - Responsive CSS Tutorial
Scrimba
4. Controlling the width of images - Responsive CSS Tutorial
Scrimba
5. min width and max width - Responsive CSS Tutorial
Scrimba
3 CSS Units. Percentage - Responsive CSS Tutorial
Scrimba
11. Flexbox refresher and setting up some HTML - Responsive CSS Tutorial
Scrimba
12. Basic Styles and setting up the columns - Responsive CSS Tutorial
Scrimba
8. The Solution Rems - Responsive CSS Tutorial
Scrimba
14. Setting the columns widths - Responsive CSS Tutorial
Scrimba
2 CSS Units - Responsive CSS Tutorial
Scrimba
7. The problem with ems - Responsive CSS Tutorial
Scrimba
6. CSS Units. The em unit - Responsive CSS Tutorial
Scrimba
13. Adding the background color - Responsive CSS Tutorial
Scrimba
9. Picking which unit to use - Responsive CSS Tutorial
Scrimba
Tutorial to Learn Alpine JS - Full Course for Beginners
Scrimba
Guide To Algorithms in Javascript [Binary Search] - Full Course / Tutorial
Scrimba
Learn UI Design [7 Fundamentals Tutorial] - Full Course for Beginners
Scrimba
Javascript Tutorial for Beginners [From 0 to ES6+] - Full Course
Scrimba
More on: HTML & CSS
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
X now offers an MCP server to make its platform easier for AI tools to use
TechCrunch AI
n8n Automation Repurpose Video Content: The 2025 Production Guide
Dev.to AI
You’re Still Paying $200/Month for AI Tools You Could Replace With a Free Local Setup Tonight
Medium · Data Science
Top 10 AI Tools Every College Student Should Know in 2026
Medium · AI
🎓
Tutor Explanation
DeepCamp AI