The min-width property in CSS is used to set the minimum width of a specified element.
The min-width property always overrides the width property whether followed before or after width in your declaration.
In the below example, 1st div element takes width of element but 2nd div element’s minimum width is 300px.
<!DOCTYPE html>
<html>
<head>
<style>
h3 {
color: maroon;
}
span {
background: #020d41;
color: #ffffff;
padding: 6px 12px;
}
span.example {
min-width: 300px;
display: inline-block;
}
</style>
</head>
<body>
<div>
<h3>min-width: none (default):</h3>
<span>Lorem ipsum dolor sit amet...</span>
</div>
<div>
<h3>min-width: 300px:</h3>
<span class="example">Lorem ipsum dolor sit amet...</span>
</div>
</body>
</html>
This will produce the following result −
The max-width property in CSS is used to set the maximum width of a specified element.
The max-width property always overrides the width property whether followed before or after width in your declaration.
In the below example, 1st div element takes width of element but 2nd div element’s maximum width is 350px.
<!DOCTYPE html>
<html>
<head>
<style>
h3 {
color: maroon;
}
p {
background: #020d41;
color: #ffffff;
padding: 6px 12px;
}
p.example {
max-width: 350px;
}
</style>
</head>
<body>
<h3>max-width: none (default):</h3>
<p>Lorem ipsum dolor sit amet...</p>
<h3>max-width: 350px:</h3>
<p class="example">Lorem ipsum dolor sit amet...</p>
</body>
</html>
This will produce the following result −