Skip to content
Home Blog Web Design CSS Box Model Explained

CSS Box Model Explained

  • Web Design
Blueprint Digital
Blueprint Digital

Insights from the Blueprint Digital team.

I love working with CSS in front end development both on personal projects and at Blueprint. Most things in CSS are pretty straightforward. However, one thing that can confuse developers, from beginners to even seasoned veterans, is the CSS box model. It is a concept that could be hard to grasp, just like the CSS z-index property or different units in font size. So what is the CSS box model, and why is it so confusing?

CSS Box Model

Pretty much all of HTML elements on a website are rectangular. The CSS box model describes how these elements are formatted using width, padding, border, and margin, and how these CSS properties work together. There are two types of CSS box models: traditional and W3C. In a traditional box model, padding and border are part of the width. Traditional box model was used by earlier versions of IE(<8). The W3C box model is the one recommended by the World Wide Web Consortium (W3C) and doesn’t include padding and border as part of the width. Most modern browsers render the elements using the W3C box model.

 

This W3C model leads to some confusion because the box model is not very intuitive. What you perceive would be the width isn’t the actual width set in CSS. For example, one would intuitively think that a width of 200px would be applied to the whole element, but in the W3C model used by modern browsers the width of 200px is only applied to the actual content area.

There is more confusion when the width isn’t explicitly set in the CSS. In both cases, if a width of a block element isn’t set, the width of the content area will be calculated by taking the width of the parent element and subtracting the other values from the parent element’s width. Because of this, CSS resets are very useful because they get rid of those paddings and whatnot that different browsers add to elements so that elements look mostly consistent in all browsers.

CSS3 box-sizing

In CSS3, there is a new property called box-sizing that can be used to set the desired box model. There are two values for the property: border-box and content-box. Border-box renders an element using the traditional box model, and content-box renders an element using the W3C box model. If you want to use the traditional box model, you can using this code:

.foo {
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
     box-sizing: border-box;
}

Conclusion

The box model is one of the important fundamentals of CSS and front end development. It may be a confusing concept to grasp, but it is necessary to understand it.

Ready to Dominate Online and Grow Your Business?

Schedule time to connect with Blueprint about your online goals, or request a free review of marketing campaigns.

Related Posts

What Is Automated Lead Follow-Up and How Does It Work

What Is Automated Lead Follow-Up and How Does It Work

A new lead fills out a form, then waits. If the phone stays silent for a day, that lead has usually moved on to whoever answered first. Automated lead follow-up closes the gap. It is a marketing automation system that responds to every new inquiry within minutes, then continues the conversation through scheduled texts, emails,[...]
Free Advertising for Nonprofits Through Google Ad Grants

Free Advertising for Nonprofits Through Google Ad Grants

Advertising is usually the first line cut from a nonprofit budget, and the one that quietly costs the most to lose. Donors still search, scroll, and read, whether or not the cause has money to meet them there. Free advertising for nonprofits means promoting a cause without paying for placements, and it is how organizations[...]
Lead Scoring for B2B: How to Decide Which Leads Your Sales Team Chases

Lead Scoring for B2B: How to Decide Which Leads Your Sales Team Chases

Every marketing team has handed sales a list of leads that went nowhere. After a few of those lists, sales stops trusting them, works its own referrals instead, and the two teams settle into a standing argument about lead quality. Underneath the argument is a simpler problem: nobody has written down what a good lead[...]
Previous
Next

Partner with BLUEPRINT to reach your online goals, grow your business and reshape your story.

Get in touch with BLUEPRINT

Reach out to request a discovery call, a free campaign review, or for all other inquiries.

Subscribe to our newsletter