-
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)
CSS Units define the measurement system used for lengths, sizes, positions, margins, paddings, font sizes, and more. There are two main types of units:
Absolute units: Fixed sizes (e.g., px
, cm
)
Relative units: Flexible sizes based on parent or viewport (e.g., em
, %
, vw
)
Unit | Description | Example |
---|---|---|
px |
Pixels | font-size: 16px; |
cm |
Centimeters | width: 10cm; |
mm |
Millimeters | height: 15mm; |
in |
Inches | width: 2in; |
pt |
Points (1/72 inch) | font-size: 12pt; |
pc |
Picas (12 points) | font-size: 1pc; |
🔹 Use absolute units when you need precise measurements, like in printing.
Unit | Description | Example |
---|---|---|
% |
Relative to parent element | width: 50%; |
em |
Relative to the element’s font-size | padding: 2em; |
rem |
Relative to the root element’s font-size | font-size: 1.5rem; |
vw |
1% of the viewport’s width | width: 80vw; |
vh |
1% of the viewport’s height | height: 90vh; |
vmin |
Smaller of vw or vh |
font-size: 4vmin; |
vmax |
Larger of vw or vh |
font-size: 4vmax; |
ch |
Width of the character 0 in the font |
width: 60ch; |
ex |
Height of lowercase x in the font |
line-height: 1ex; |
🔹 Use relative units for responsive design and accessibility.
em
vs rem
html {
font-size: 16px;
}
div {
font-size: 2em; /* 32px (relative to parent) */
}
p {
font-size: 1.5rem; /* 24px (relative to root) */
}
.section {
height: 100vh; /* Full screen height */
width: 100vw; /* Full screen width */
}
Q1. Set a div
width to 500 pixels.
Q2. Set font size to 2em inside a div
.
Q3. Make a section full height of the screen using vh
.
Q4. Set padding as 10% of the parent width.
Q5. Make a container 60 characters wide using ch
.
Q6. Use rem
to define font size of 24px (assuming root is 16px).
Q7. Set image width to 80% of its parent.
Q8. Create a box that is 5cm wide and 2in tall.
Q9. Use vmin
to adjust font-size for small screens.
Q10. Create two divs with widths 60vw
and 40vw
side by side.
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)