{"id":78,"date":"2026-04-06T18:12:34","date_gmt":"2026-04-06T18:12:34","guid":{"rendered":"https:\/\/gigz.pk\/css\/?post_type=lesson&#038;p=78"},"modified":"2026-04-18T16:14:03","modified_gmt":"2026-04-18T16:14:03","slug":"css-box-sizing","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/css\/lesson\/css-box-sizing\/","title":{"rendered":"CSS Box Sizing"},"content":{"rendered":"\n<p>Box sizing is an important concept in CSS that controls how the total width and height of an element are calculated. It helps you manage layouts more easily and avoid unexpected sizing issues.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is Box Sizing<\/h3>\n\n\n\n<p>By default, CSS uses the content box model. This means that width and height only apply to the content area, and padding and border are added outside of it. This can make elements larger than expected.<\/p>\n\n\n\n<p>Box sizing allows you to change this behavior so that padding and border are included inside the defined width and height.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Types of Box Sizing<\/h3>\n\n\n\n<p>There are two main values used in box sizing.<\/p>\n\n\n\n<p>Content box<br>This is the default value. The width and height only include the content. Padding and border increase the total size of the element.<\/p>\n\n\n\n<p>Example<br>If width is 200 pixels and padding is 20 pixels, the total width becomes 240 pixels.<\/p>\n\n\n\n<p>Border box<br>This value includes content, padding, and border within the specified width and height. It keeps the layout more predictable.<\/p>\n\n\n\n<p>Example<br>If width is 200 pixels and padding is 20 pixels, the total width remains 200 pixels.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Syntax<\/h3>\n\n\n\n<p>box sizing property is applied like this<\/p>\n\n\n\n<p>box sizing colon value<\/p>\n\n\n\n<p>Example in CSS<\/p>\n\n\n\n<p>box sizing border box<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why Use Border Box<\/h3>\n\n\n\n<p>Using border box makes layout design easier and more consistent. It prevents elements from growing beyond their assigned size when padding or borders are added. This is especially useful in responsive design.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Global Best Practice<\/h3>\n\n\n\n<p>Most developers apply border box to all elements to simplify layout control.<\/p>\n\n\n\n<p>Example<\/p>\n\n\n\n<p>star selector<br>box sizing border box<\/p>\n\n\n\n<p>This ensures every element follows the same sizing rule.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Practical Example<\/h3>\n\n\n\n<p>Without border box, two elements with the same width may appear different because of padding and borders. With border box, they stay equal in size and align properly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">When to Use Box Sizing<\/h3>\n\n\n\n<p>Use border box for most layout designs and responsive websites.<br>Use content box only when you specifically need the default behavior.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Summary<\/h3>\n\n\n\n<p>Box sizing controls how element dimensions are calculated.<br>Content box adds padding and border outside the width.<br>Border box includes everything inside the width.<br>Using border box makes layouts easier and more predictable.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/css\/\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">CSS Fundamentals (Beginner) > Box Model > Box Sizing<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1776528732134\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1776528732386\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1776528731894\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n","protected":false},"menu_order":0,"template":"","class_list":["post-78","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>CSS Box Sizing - CSS learning mastery<\/title>\n<meta name=\"description\" content=\"Learn CSS box sizing with simple examples. Understand border box and content box to control layout and improve responsive design.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/css\/lesson\/css-box-sizing\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"CSS Box Sizing - CSS learning mastery\" \/>\n<meta property=\"og:description\" content=\"Learn CSS box sizing with simple examples. Understand border box and content box to control layout and improve responsive design.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/css\/lesson\/css-box-sizing\/\" \/>\n<meta property=\"og:site_name\" content=\"CSS learning mastery\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-18T16:14:03+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/css-box-sizing\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/css-box-sizing\\\/\",\"name\":\"CSS Box Sizing - CSS learning mastery\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/#website\"},\"datePublished\":\"2026-04-06T18:12:34+00:00\",\"dateModified\":\"2026-04-18T16:14:03+00:00\",\"description\":\"Learn CSS box sizing with simple examples. Understand border box and content box to control layout and improve responsive design.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/css-box-sizing\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/css-box-sizing\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/css-box-sizing\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/css\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"CSS Fundamentals (Beginner) > Box Model > Box Sizing\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/css\\\/\",\"name\":\"CSS learning mastery\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/css\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"CSS Box Sizing - CSS learning mastery","description":"Learn CSS box sizing with simple examples. Understand border box and content box to control layout and improve responsive design.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/css\/lesson\/css-box-sizing\/","og_locale":"en_US","og_type":"article","og_title":"CSS Box Sizing - CSS learning mastery","og_description":"Learn CSS box sizing with simple examples. Understand border box and content box to control layout and improve responsive design.","og_url":"https:\/\/gigz.pk\/css\/lesson\/css-box-sizing\/","og_site_name":"CSS learning mastery","article_modified_time":"2026-04-18T16:14:03+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/css\/lesson\/css-box-sizing\/","url":"https:\/\/gigz.pk\/css\/lesson\/css-box-sizing\/","name":"CSS Box Sizing - CSS learning mastery","isPartOf":{"@id":"https:\/\/gigz.pk\/css\/#website"},"datePublished":"2026-04-06T18:12:34+00:00","dateModified":"2026-04-18T16:14:03+00:00","description":"Learn CSS box sizing with simple examples. Understand border box and content box to control layout and improve responsive design.","breadcrumb":{"@id":"https:\/\/gigz.pk\/css\/lesson\/css-box-sizing\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/css\/lesson\/css-box-sizing\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/css\/lesson\/css-box-sizing\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/css\/"},{"@type":"ListItem","position":2,"name":"CSS Fundamentals (Beginner) > Box Model > Box Sizing"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/css\/#website","url":"https:\/\/gigz.pk\/css\/","name":"CSS learning mastery","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/css\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/css\/wp-json\/wp\/v2\/lesson\/78","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/css\/wp-json\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/css\/wp-json\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/css\/wp-json\/wp\/v2\/media?parent=78"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}