CSS – Set Width for Div
To set a specific width for Div element using CSS, set width property with required value for the selected div elements in styles(inline/external).
Example
In the following HTML script, we have set width property for div elements with different values.
index.html
</>
Copy
<!DOCTYPE html>
<html lang="en">
<head>
<style>
div {
background-color: red;
height: 50px;
margin: 10px 0;
}
#div1 {
width: 50px;
}
#div2 {
width: 150px;
}
#div3 {
width: 250px;
}
</style>
</head>
<body>
<div>Div</div>
<div id="div1">Div 1</div>
<div id="div2">Div 2</div>
<div id="div3">Div 3</div>
</body>
</html>
Conclusion
In this CSS Tutorial, we learned how to set width for Div element(s) using CSS.