CSS max-width property

CSS max-width Property

Description

The max-width property sets an upper limit on the width of an element.

Possible Values

  • length – Any length unit. The width of the element will not exceed this distance.
  • percentage – Limits the width of an element to a percentage of the containing block’s width.


  • none – There is no limit on the width of the element.

Applies to

Applies to all HTML elements except non-replaced inline elements and tables.

DOM syntax

object.style.maxWidth = "50px" 

Example

This is an example –

<html> 
<head> 
</head> 

<body> 
<p style = "max-width:100px; height:200px; border:1px solid red; padding:5px; margin:10px;"> 
This paragraph is 200px high and max width is 100px 
This paragraph is 200px high and max width is 100px 
This paragraph is 200px high and max width is 100px 
This paragraph is 200px high and max width is 100px 
This paragraph is 200px high and max width is 100px 
</p> 

<img alt = "logo" src = "/https://coder-cafe.com/wp-content/uploads/2025/09/images/css.gif" width = "95" height = "84" /> </body> 

This will produce the following result −

CSS max-width property

Leave a Reply

Your email address will not be published. Required fields are marked *