CSS Max-width:
The max-width property in CSS is used to define the maximum width of an element. The value of the width cannot be larger than the value by max-width. If the content is larger than the max-width then it will go to the next line and if the content is smaller than the max-width then it has no effect.
Syntax:
max-width: none | length | percentage (%) | initial | inherit;
Property Values: All the properties are described well in the example below.
none: It is the default value and it does not contain max-width.
length: This property is used to set the length of max-width. The length can be set in the form of px, cm, etc.
percentage (%): This property is used to set the max-width in the form of a percentage.
initial: It is used to set an element’s CSS property to its default value. The initial keyword can be used for any CSS property, and on any HTML element.
inherit: This property is used to inherit a property to an element from its parent element property value. The inherit keyword can be used for inheriting any CSS property, and on any HTML element.
Example: This example illustrates the use of the max-width property whose value is set to none.
<!DOCTYPE html>
<html>
<head>
<title>max-width property</title>
<!-- max-width CSS property -->
<style>
p {
max-width: none;
color: white;
background-color: pink;
}
</style>
</head>
<body>
<p> Gocources: it's a online subject</p>
</body>
</html>
Output:
Gocources: it's a online subject