Course Content
CSS Basic
0/1
CSS Selectors
0/1
CSS Comments
0/1
CSS Backgrounds
0/1
CSS Borders
0/1
CSS Outline
0/1
CSS Fonts
0/1
CSS Icons
0/1
CSS Links
0/1
CSS Lists
0/1
CSS Tables
0/1
CSS Display Properties
0/1
CSS Positioning Elements
0/1
CSS Z-Index Property
0/1
CSS Overflow
0/1
CSS Float
0/1
CSS Opacity
0/1
CSS Dropdowns
0/1
CSS Buttons
0/1
CSS Media Queries
0/1
About Lesson

max-width and min-width:

Definition:

  • max-width sets the maximum width an element can expand to.
  • min-width sets the minimum width an element must be, even if the screen is small.

Syntax:

selector {
  max-width: value;
  min-width: value;
}
/*value can be in units like px, %, em, rem, etc.*/

Example:

HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <style>
    .wide-box {
      min-width: 150px;
      max-width: 400px;
      background-color: lightyellow;
      border: 2px solid orange;
      padding: 10px;
      margin: 20px auto;
    }
  </style>
  <title>Max and Min Width Example</title>
</head>
<body>
  <div class="wide-box">
    This box has a minimum width of 150px and a maximum width of 400px. Resize the browser window to see the effect.
  </div>
</body>
</html>