CSS Box Model Explained (Margin, Border, Padding)
When you start styling websites with CSS, one concept you must understand clearly is the CSS Box Model . Almost every element in HTML is treated like a rectangular box, and understanding how this box works will make layout and spacing much easier. If your elements are not aligning properly or spacing looks weird — the Box Model is usually the reason. Let’s break it down in simple terms. What is the CSS Box Model? In CSS, every element is considered a box made up of four layers: Content Padding Border Margin Think of it like this: Margin Border Padding Content Each layer plays a different role in spacing and design. 1. Content This is the actual text, image, or data inside the element. Example: div { width : 300px ; height : 100px ; } The width and height apply to the content area by default. 2. Padding (Inner Space) Padding is the space inside the element , between the content and the border. div { padding : 20px ; } This ad...