Open In App

Explain the purpose of the max-width Property

The max-width property in CSS is used to set the maximum width of an element. It is commonly applied to ensure that an element does not exceed a specified width, providing control over the layout and responsiveness of a web page.

The max-width property can be applied to various elements, such as images or containers, limiting their width.

Syntax:

/* Setting a maximum width for an image */
img {
max-width: 100%;
}

/* Restricting the maximum width of a container */
.container {
max-width: 800px;
}

Features:

Article Tags :