-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
CSS Basics
CSS Styling Properties
CSS Box Model
CSS Margin
CSS Padding
CSS Borders
CSS Outline
CSS Height/Width
CSS Max-width
CSS Display
CSS Position
CSS Z-index
CSS Overflow
CSS Float
CSS Inline-block
CSS Align
CSS Box Sizing
CSS Text
CSS Fonts
CSS Icons
CSS Text Effects
CSS Web Fonts
CSS Colors
CSS Backgrounds
CSS Color Keywords
CSS Gradients
CSS Shadows
CSS Links
CSS Lists
CSS Tables
CSS Advanced Selectors & Features
CSS Combinators
CSS Pseudo-classes
CSS Pseudo-elements
CSS Attribute Selectors
CSS Specificity
CSS !important
CSS Units
CSS Variables
CSS @property
CSS Math Functions
CSS Media and Image Styling
CSS Image Styling
CSS Image Centering
CSS Image Filters
CSS Image Shapes
CSS object-fit
CSS object-position
CSS Masking
CSS Layout Techniques
CSS Website Layout
CSS Navigation Bar
CSS Dropdowns
CSS Image Gallery
CSS Counters
CSS Pagination
CSS Multiple Columns
CSS User Interface
CSS Flexbox
CSS Grid
CSS Responsive Design (RWD)
The height
and width
properties in CSS are used to define the size of an element’s content area.
By default, padding, borders, and margins are not included in height and width (unless you use box-sizing: border-box
).
element {
width: 300px;
height: 150px;
}
Pixels (px)
Percent (%)
View Width (vw)
View Height (vh)
em, rem, etc.
Value | Description |
---|---|
auto |
Default. The browser calculates it |
px |
Fixed size in pixels |
% |
Percentage of the containing element |
max-content |
Size based on the longest content |
min-content |
Smallest size the content fits into |
You can also use:
max-width: 500px;
min-width: 200px;
max-height: 300px;
min-height: 100px;
✅ Prevents the element from shrinking too small or growing too large.
box-sizing: border-box
To include padding and border in the width/height:
* {
box-sizing: border-box;
}
✅ Ensures your element doesn’t overflow due to padding and border.
Q1. Set the width of a <div>
to 400px.
Q2. Make a <section>
have a height of 200px.
Q3. Set the width of a container to 50% of the page.
Q4. Add min-width: 300px
and max-width: 800px
to a .card
.
Q5. Create a responsive box with width 80vw
and height 50vh
.
Q6. Prevent an image from exceeding 100% of its parent width.
Q7. Set the height of a <textarea>
to 150px and width to 100%.
Q8. Write a rule to limit a div’s height to 500px but not less than 300px.
Q9. Apply box-sizing: border-box
to all elements on the page.
Q10. Use inline CSS to set width: 200px for a paragraph.
CSS Basics
CSS Styling Properties
CSS Box Model
CSS Margin
CSS Padding
CSS Borders
CSS Outline
CSS Height/Width
CSS Max-width
CSS Display
CSS Position
CSS Z-index
CSS Overflow
CSS Float
CSS Inline-block
CSS Align
CSS Box Sizing
CSS Text
CSS Fonts
CSS Icons
CSS Text Effects
CSS Web Fonts
CSS Colors
CSS Backgrounds
CSS Color Keywords
CSS Gradients
CSS Shadows
CSS Links
CSS Lists
CSS Tables
CSS Advanced Selectors & Features
CSS Combinators
CSS Pseudo-classes
CSS Pseudo-elements
CSS Attribute Selectors
CSS Specificity
CSS !important
CSS Units
CSS Variables
CSS @property
CSS Math Functions
CSS Media and Image Styling
CSS Image Styling
CSS Image Centering
CSS Image Filters
CSS Image Shapes
CSS object-fit
CSS object-position
CSS Masking
CSS Layout Techniques
CSS Website Layout
CSS Navigation Bar
CSS Dropdowns
CSS Image Gallery
CSS Counters
CSS Pagination
CSS Multiple Columns
CSS User Interface
CSS Flexbox
CSS Grid
CSS Responsive Design (RWD)