/

HTML / CSS / JavaScript Tutorial

CSS Property: min-width

[this page | pdf | back links]

The CSS (CSS2) min-width property sets the minimum width an element can become. It overrides the width property and the max-width property.

 

Valid property values (other than inherit and initial) are:

 

Value

Description

length

A CSS length

%

Defined as a percentage of that of the containing block

none

(default value). No limit

 

Default Value:

none

JavaScript syntax:

e.g. object.style.minWidth="150px"

Inherited:

No

Animatable:

Yes

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
p {width: 100px; overflow: auto; background-color: yellow;}
p.x1 {min-width: 300px;}
</style>
</head>
<body>
<p>Element with default property</p>
<p class="x1">Property set using in-file HTML style</p>
<p id="x2">Property set using JavaScript</p>

<script>
document.getElementById("x2").style.minWidth = "300px";
</script>

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedCSSPropertyMinWidth() {
  var x = document.createElement("DIV"); x.style.minWidth = "300px"; return (window.getComputedStyle(x, null).minWidth == "300px");
}


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile