Home
CSS
CSS Float
Examples
Tryit: Float boxes side by side
Run ❯
Get your
own
website
Result Size:
625 x 534
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <head> <style> * { box-sizing: border-box; } .box { float: left; width: 33.33%; padding: 50px; } .clearfix::after { content: ""; clear: both; display: table; } </style> </head> <body> <h2>Grid of Boxes</h2> <p>Float boxes side by side:</p> <div class="clearfix"> <div class="box" style="background-color:#bbb"> <p>Some text inside the box.</p> </div> <div class="box" style="background-color:#ccc"> <p>Some text inside the box.</p> </div> <div class="box" style="background-color:#ddd"> <p>Some text inside the box.</p> </div> </div> <p><strong>Note:</strong> Here, we use the clearfix hack to take care of the layout flow. We also use the box-sizing property to make sure that the box doesn't break due to extra padding. Try to remove this code to see the effect.</p> </body> </html>