SlideShare a Scribd company logo
CSS Box Model
What is the CSS Box Model? The “Box Model” is a tool we use to lay out our web pages in a number of individual "boxes" or "containers".  When we plan our web page design, we must take into account not only the size of page content, but also the margins, borders, and padding involved. Before we start building a page, we can plan where everything will go by arranging these boxes on the screen.  Our goal is to create a balanced layout, with plenty of "white space" around the content.
The components of a box: Margin Border Content Padding
Introducing the <div> tag: The <div> tag is our basic building block when laying out a page design.  By defining the height and width of the <div>, we are &quot;reserving&quot; that amount of space on the screen for whatever content we wish to place there. The actual content will go inside the opening <div> and closing </div> tags.
Example <div>: By establishing the box dimensions, we can leave it there as a placeholder until we have our content ready.  In the meantime, the rest of the page can be built out with our other content. <head> <style type=&quot;text/css&quot;> .box300 { width:300px; height:300px; border:1px solid black; } </style> </head> <div class=&quot;box300&quot;> This is a 300 by 300 pixel box with a 1px border. </div> This is outside the box. This is a 300 by 300 pixel box with a 1 px border. This is outside the box.
Adding padding: By adding 10px of padding on all four sides of the content, we have effectively made our box 320px by 320px (321px by 321px with the border). <head> <style type=&quot;text/css&quot;> .box300 { width:300px; height:300px; border:1px solid black; padding:10px; } </style> </head> <div class=&quot;box300&quot;> This is a 300 by 300 pixel box with a 1px border and 10px padding. </div> <p>This is outside the box.</p> This is a 300 by 300 pixel box with a 1px border and 10px padding. This is outside the box.
Adding margin: By adding 10px of margin on all four sides of the border, we have now made our box 341px by 341px overall. <head> <style type=&quot;text/css&quot;> .box300 { width:300px; height:300px; border:1px solid black; padding:10px; margin:10px; } </style> </head> <div class=&quot;box300&quot;> This is a 300 by 300 pixel box with a 1px border and 10px Padding and 10px margin. </div> <p>This is outside the box.</p> This is a 300 by 300 pixel box with a 1px border and 10px padding and 10px margin. This is outside the box. The dotted line here shows where the margin is but it will not show on the actual page.
Calculating overall dimensions: When designing our page, we have to calculate how much size a <div> element will consume: Total element width = defined width + left padding + right padding + left border + right border + left margin + right margin. Total element height = defined height + top padding + bottom padding + top border + bottom border + top margin + bottom margin
Pixels vs. Percent: The width property can be specified in pixels or in percent.  By using &quot;width:50%&quot;, we are telling the browser to make the width of the element exactly 50% of the space available. Using percent instead of pixels can make our page layout highly flexible.  For example, we can use the entire screen real estate, no matter what size screen or resolution our web visitor has.
A technique to center a <div>: Because we don't know what the screen resolution will be for our visitors, it can be challenging to get our pages to display attractively for all viewers. A useful technique is to set the right and left margins of a <div> to the value &quot;auto&quot;.  This tells the browser to maintain an equal distance on the right and left, effectively centering the <div> no matter how wide the available area is: .centerme {   margin:0 auto; } This same technique can be used on a <div> element that contains all your page content in order to center your page on the screen, no matter what the screen resolution of your web visitor.

More Related Content

What's hot (20)

PPTX
HTML/HTML5
People Strategists
 
PPTX
Javascript operators
Mohit Rana
 
PPTX
Css position
Webtech Learning
 
PDF
Generics
Ravi_Kant_Sahu
 
PPT
Advanced Cascading Style Sheets
fantasticdigitaltools
 
PPTX
HTML Table Tags
Kainat Ilyas
 
PPTX
C# 101: Intro to Programming with C#
Hawkman Academy
 
PPT
Entity relationship modelling
Dr. C.V. Suresh Babu
 
ODP
Datatype in JavaScript
Rajat Saxena
 
PDF
Database Models.pdf
nirmalraj murugaiyan
 
PPT
Python GUI Programming
RTS Tech
 
PPSX
Collections - Array List
Hitesh-Java
 
PPTX
Principles and advantages of oop ppt
daxesh chauhan
 
PPTX
Classes, objects in JAVA
Abhilash Nair
 
PPTX
relational algebra (joins)
Nilt1234
 
PPTX
Java script arrays
Frayosh Wadia
 
PPT
Eye catching HTML BASICS tips: Learn easily
shabab shihan
 
PDF
JDBC : Java Database Connectivity
DevAdnani
 
HTML/HTML5
People Strategists
 
Javascript operators
Mohit Rana
 
Css position
Webtech Learning
 
Generics
Ravi_Kant_Sahu
 
Advanced Cascading Style Sheets
fantasticdigitaltools
 
HTML Table Tags
Kainat Ilyas
 
C# 101: Intro to Programming with C#
Hawkman Academy
 
Entity relationship modelling
Dr. C.V. Suresh Babu
 
Datatype in JavaScript
Rajat Saxena
 
Database Models.pdf
nirmalraj murugaiyan
 
Python GUI Programming
RTS Tech
 
Collections - Array List
Hitesh-Java
 
Principles and advantages of oop ppt
daxesh chauhan
 
Classes, objects in JAVA
Abhilash Nair
 
relational algebra (joins)
Nilt1234
 
Java script arrays
Frayosh Wadia
 
Eye catching HTML BASICS tips: Learn easily
shabab shihan
 
JDBC : Java Database Connectivity
DevAdnani
 

Viewers also liked (20)

PDF
Css box model
Nicha Jutasirivongse
 
PPTX
The CSS Box Model
Graeme Smith
 
PPSX
CSS Box Model Presentation
Reed Crouch
 
PDF
CSS Box Model
Gerson Abesamis
 
PDF
CSS Layouting #3 : Box Model
Sandhika Galih
 
PPT
CSS, CSS Selectors, CSS Box Model
jamiecavanaugh
 
PPTX
The Box Model [CSS Introduction]
Nicole Ryan
 
PDF
CSS Box Model and Dimensions
Gerson Abesamis
 
PPTX
CSS Layout Techniques
Harshal Patil
 
PPTX
Google's Principle's of Mobile Website Design
Mrkt360 Inc.
 
PPTX
Introduction about wireframing and responsive webdesign
ipmindthegap
 
KEY
Lecture3
Lee Lundrigan
 
PDF
Next Steps in Responsive Design
Justin Avery
 
KEY
Interactive Graphics using Javascript, HTML5 and CSS3
Lee Lundrigan
 
PPT
Webdesign New
lyngdoh
 
PPTX
10 Design and Layout Principles Guaranteed to Improve Your Website V2
Lauren Martin
 
PDF
CSS Dasar #6 : Background
Sandhika Galih
 
PPT
Css page layout
Thiện Thành Thật
 
PPTX
Introduction to computers
Akash Varaiya
 
PPT
Page Layout 2010
Cathie101
 
Css box model
Nicha Jutasirivongse
 
The CSS Box Model
Graeme Smith
 
CSS Box Model Presentation
Reed Crouch
 
CSS Box Model
Gerson Abesamis
 
CSS Layouting #3 : Box Model
Sandhika Galih
 
CSS, CSS Selectors, CSS Box Model
jamiecavanaugh
 
The Box Model [CSS Introduction]
Nicole Ryan
 
CSS Box Model and Dimensions
Gerson Abesamis
 
CSS Layout Techniques
Harshal Patil
 
Google's Principle's of Mobile Website Design
Mrkt360 Inc.
 
Introduction about wireframing and responsive webdesign
ipmindthegap
 
Lecture3
Lee Lundrigan
 
Next Steps in Responsive Design
Justin Avery
 
Interactive Graphics using Javascript, HTML5 and CSS3
Lee Lundrigan
 
Webdesign New
lyngdoh
 
10 Design and Layout Principles Guaranteed to Improve Your Website V2
Lauren Martin
 
CSS Dasar #6 : Background
Sandhika Galih
 
Css page layout
Thiện Thành Thật
 
Introduction to computers
Akash Varaiya
 
Page Layout 2010
Cathie101
 
Ad

Similar to 5.1 css box model (20)

PDF
11--CSS-Box-Model.pdf for second college
shwan it
 
PDF
GDI Seattle Intro to HTML and CSS - Class 3
Heather Rock
 
PDF
Web Layout
Shawn Calvert
 
PDF
Box Model and Page Layouts
Vidya Ananthanarayanan
 
KEY
Css Essential
Yue Tian
 
PPTX
Chapter 14: Box Model
Steve Guinan
 
PPTX
Pres
Andrey L
 
PPTX
Cascading style sheets (CSS-Web Technology)
Timbal Mayank
 
PPT
Box Model
Amit Kumar Singh
 
PDF
Dimensions of elements.pdf
Kongu Engineering College, Perundurai, Erode
 
PPTX
Css box model
Dhairya Joshi
 
PPTX
Week 3
A VD
 
PDF
Layout with CSS
Mike Crabb
 
PPTX
Lecture 6.pptx..........................
salmannawaz6566504
 
PPTX
CSS: Box Model
utsav singh
 
PPT
Advance Css 1194323118268797 5
dharshyamal
 
PPT
Advance Css
vijayta
 
PPTX
CSS3 notes
Rex Wang
 
PPTX
Pixel to Percentage conversion Convert left and right padding of a div to per...
vishal choudhary
 
PPTX
CSS.pptx
RajKumarRock3
 
11--CSS-Box-Model.pdf for second college
shwan it
 
GDI Seattle Intro to HTML and CSS - Class 3
Heather Rock
 
Web Layout
Shawn Calvert
 
Box Model and Page Layouts
Vidya Ananthanarayanan
 
Css Essential
Yue Tian
 
Chapter 14: Box Model
Steve Guinan
 
Pres
Andrey L
 
Cascading style sheets (CSS-Web Technology)
Timbal Mayank
 
Box Model
Amit Kumar Singh
 
Css box model
Dhairya Joshi
 
Week 3
A VD
 
Layout with CSS
Mike Crabb
 
Lecture 6.pptx..........................
salmannawaz6566504
 
CSS: Box Model
utsav singh
 
Advance Css 1194323118268797 5
dharshyamal
 
Advance Css
vijayta
 
CSS3 notes
Rex Wang
 
Pixel to Percentage conversion Convert left and right padding of a div to per...
vishal choudhary
 
CSS.pptx
RajKumarRock3
 
Ad

More from Bulldogs83 (19)

PPT
7.2 external style sheets
Bulldogs83
 
PPT
7.1 xhtml validation
Bulldogs83
 
PPT
6.2 css link styling
Bulldogs83
 
PPT
6.1 special characters
Bulldogs83
 
PPT
5.2 nesting and floating elements
Bulldogs83
 
PPT
4.3 table styling
Bulldogs83
 
PPT
4.2 css classes
Bulldogs83
 
PPT
4.1 advanced tables
Bulldogs83
 
PPT
3.2 introduction to css
Bulldogs83
 
PPT
3.1 xhtml tables
Bulldogs83
 
PPT
3.2 introduction to css
Bulldogs83
 
PPT
2.1 adding images
Bulldogs83
 
PPT
1.4 adding comments copy (2)
Bulldogs83
 
PPT
1.4 adding comments copy (2)
Bulldogs83
 
PPT
1.3 creating links
Bulldogs83
 
PPT
1.3 creating links
Bulldogs83
 
PPT
1.2 elements and attributes copy (3)
Bulldogs83
 
PPT
1.2 elements and attributes copy (3)
Bulldogs83
 
PPT
1.1 xhtml basics
Bulldogs83
 
7.2 external style sheets
Bulldogs83
 
7.1 xhtml validation
Bulldogs83
 
6.2 css link styling
Bulldogs83
 
6.1 special characters
Bulldogs83
 
5.2 nesting and floating elements
Bulldogs83
 
4.3 table styling
Bulldogs83
 
4.2 css classes
Bulldogs83
 
4.1 advanced tables
Bulldogs83
 
3.2 introduction to css
Bulldogs83
 
3.1 xhtml tables
Bulldogs83
 
3.2 introduction to css
Bulldogs83
 
2.1 adding images
Bulldogs83
 
1.4 adding comments copy (2)
Bulldogs83
 
1.4 adding comments copy (2)
Bulldogs83
 
1.3 creating links
Bulldogs83
 
1.3 creating links
Bulldogs83
 
1.2 elements and attributes copy (3)
Bulldogs83
 
1.2 elements and attributes copy (3)
Bulldogs83
 
1.1 xhtml basics
Bulldogs83
 

Recently uploaded (20)

PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 

5.1 css box model

  • 2. What is the CSS Box Model? The “Box Model” is a tool we use to lay out our web pages in a number of individual &quot;boxes&quot; or &quot;containers&quot;. When we plan our web page design, we must take into account not only the size of page content, but also the margins, borders, and padding involved. Before we start building a page, we can plan where everything will go by arranging these boxes on the screen. Our goal is to create a balanced layout, with plenty of &quot;white space&quot; around the content.
  • 3. The components of a box: Margin Border Content Padding
  • 4. Introducing the <div> tag: The <div> tag is our basic building block when laying out a page design. By defining the height and width of the <div>, we are &quot;reserving&quot; that amount of space on the screen for whatever content we wish to place there. The actual content will go inside the opening <div> and closing </div> tags.
  • 5. Example <div>: By establishing the box dimensions, we can leave it there as a placeholder until we have our content ready. In the meantime, the rest of the page can be built out with our other content. <head> <style type=&quot;text/css&quot;> .box300 { width:300px; height:300px; border:1px solid black; } </style> </head> <div class=&quot;box300&quot;> This is a 300 by 300 pixel box with a 1px border. </div> This is outside the box. This is a 300 by 300 pixel box with a 1 px border. This is outside the box.
  • 6. Adding padding: By adding 10px of padding on all four sides of the content, we have effectively made our box 320px by 320px (321px by 321px with the border). <head> <style type=&quot;text/css&quot;> .box300 { width:300px; height:300px; border:1px solid black; padding:10px; } </style> </head> <div class=&quot;box300&quot;> This is a 300 by 300 pixel box with a 1px border and 10px padding. </div> <p>This is outside the box.</p> This is a 300 by 300 pixel box with a 1px border and 10px padding. This is outside the box.
  • 7. Adding margin: By adding 10px of margin on all four sides of the border, we have now made our box 341px by 341px overall. <head> <style type=&quot;text/css&quot;> .box300 { width:300px; height:300px; border:1px solid black; padding:10px; margin:10px; } </style> </head> <div class=&quot;box300&quot;> This is a 300 by 300 pixel box with a 1px border and 10px Padding and 10px margin. </div> <p>This is outside the box.</p> This is a 300 by 300 pixel box with a 1px border and 10px padding and 10px margin. This is outside the box. The dotted line here shows where the margin is but it will not show on the actual page.
  • 8. Calculating overall dimensions: When designing our page, we have to calculate how much size a <div> element will consume: Total element width = defined width + left padding + right padding + left border + right border + left margin + right margin. Total element height = defined height + top padding + bottom padding + top border + bottom border + top margin + bottom margin
  • 9. Pixels vs. Percent: The width property can be specified in pixels or in percent. By using &quot;width:50%&quot;, we are telling the browser to make the width of the element exactly 50% of the space available. Using percent instead of pixels can make our page layout highly flexible. For example, we can use the entire screen real estate, no matter what size screen or resolution our web visitor has.
  • 10. A technique to center a <div>: Because we don't know what the screen resolution will be for our visitors, it can be challenging to get our pages to display attractively for all viewers. A useful technique is to set the right and left margins of a <div> to the value &quot;auto&quot;. This tells the browser to maintain an equal distance on the right and left, effectively centering the <div> no matter how wide the available area is: .centerme { margin:0 auto; } This same technique can be used on a <div> element that contains all your page content in order to center your page on the screen, no matter what the screen resolution of your web visitor.