-
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 Variables, also known as custom properties, are entities defined by authors that contain specific values to be reused throughout a document.
They help make styles more maintainable, reusable, and easier to update.
:root {
--main-color: #3498db;
--font-size: 18px;
}
h1 {
color: var(--main-color);
font-size: var(--font-size);
}
Variables start with --
Access them using var(--variable-name)
Declare them inside :root
for global access
:root {
--bg-color: #fff;
}
Accessible from anywhere in the CSS.
.card {
--padding: 20px;
padding: var(--padding);
}
Only accessible within .card
and its children.
color: var(--primary-color, blue);
If --primary-color
is not defined, blue will be used.
document.documentElement.style.setProperty('--main-color', 'red');
CSS variables are dynamic and can be changed via JavaScript at runtime.
Reusability
Centralized control
Easy theme management (light/dark modes)
JavaScript-friendly
:root {
--bg-color: #ffffff;
--text-color: #000000;
}
.dark-theme {
--bg-color: #000000;
--text-color: #ffffff;
}
body {
background-color: var(--bg-color);
color: var(--text-color);
}
Switch .dark-theme
class to activate dark mode.
Q1. Create a variable for primary color and apply it to headings.
Q2. Define a --radius
and use it for button border-radius.
Q3. Use --font-base
for font size of all paragraphs.
Q4. Add --box-shadow
for cards and apply it.
Q5. Define a fallback for an undefined variable.
Q6. Set --container-width
and use it in a .container
class.
Q7. Change --main-color
dynamically using JavaScript.
Q8. Create light and dark themes using CSS variables.
Q9. Apply --gap
between grid columns.
Q10. Make a reusable --transition-speed
variable and apply it to links.
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)