Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>CSS Set Maximum Width of an Element</title> <style> div { width: 300px; max-width: 200px; background: #bbb3ff; } p { float: left; max-width: 400px; background: #eee8aa; } </style> </head> <body> <div>The maximum width of this div element is set to 200px, so it can't be wider than that.</div> <p>Enter some text to see how it works.</p> </body> </html>