

I would love a different box model! I find it bizarre that padding and border add the width of an object, and would love to be able to give something like a textarea 100% width and 3px padding without worrying what it’s going to do the layout. The great designer Jon Hicks, known for his excellent fluid width designs, had this to say on the subject in the CSS Wishlist we put together in 2008:
#WEBKIT MARGIN BEFORE UPDATE#
The problem for present-day developers is that those absolute pixel lengths don’t translate to responsive design, so the same math doesn’t apply anymore.Īs responsive design (or, as it was once known, “fluid” or “liquid” layout) started to gain popularity, developers and designers wished for an update to the box model. You could do a bit of arithmetic to figure out how many pixels you needed to trim off of an element’s declared width or height to accommodate its padding and border. Having the actual visible width of a box turn out differently from what you declared in the CSS is a bit mind bending.īut, in the days of fixed-width design, it wasn’t particularly complicated to work with the default box model once you understood it. Some people preferred this “quirky” interpretation of the box model and considered it more intuitive. The box at the bottom shows what was once the “quirks mode” interpretation of the box model. The box at the top shows the default box model. The border and padding values were moved inside the element's box, cutting into the width/height of the box rather than expanding it. Height = actual visible/rendered height of an element's box Width = actual visible/rendered width of an element's box This can be a little counter-intuitive, since the width and height you set for an element both go out the window as soon as you start adding padding and borders to the element.īack in the old days of web design, early versions of Internet Explorer (<= IE6) handled the box model differently when it was in "quirks mode". Height + padding + border = actual visible/rendered height of an element’s box Width + padding + border = actual visible/rendered width of an element’s box Since the dawn of CSS, the box model has worked like this by default:

It’s such a boon for developers that here at CSS-Tricks we observe International Box-Sizing Awareness Day in February.īut, how is it so helpful and beloved that it deserves its own internet holiday? Time for a little bit of CSS history. The box-sizing property can make building CSS layouts easier and a lot more intuitive.
