That’s fascinating! I will show how to use CSS variables (or called as CSS custom properties) with examples. 😊
They let you manage and reuse value with in your stylesheets which makes it easier for updates to the code.
Create CSS Variables The syntax of a CSS variable is quite simple, it starts with –, for example: and use variables Assumeyour need to provide same box-shadow values in many places.
“Master CSS with our ‘CSS Complete Guide‘ course – your ultimate resource for creating stunning, responsive web designs effortlessly!”

Table of Contents
Defining CSS Variables:
CSS variables are defined using the --
prefix and are typically declared within the :root
selector, which represents the document’s root element. This makes the variables global, meaning they can be accessed anywhere in the CSS.
Example
:root {
--main-bg-color: #f0f0f0;
--main-text-color: #333333;
--main-padding: 10px;
}
Using CSS Variables
Once you’ve declared your CSS variables, you can use them with the var()
function.
body {
background-color: var(--main-bg-color);
color: var(--main-text-color);
padding: var(--main-padding);
}
Here’s a complete example demonstrating the use of CSS variables:
Html Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Variables Example</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>Welcome to My Website</h1>
</header>
<main>
<p>This is a sample paragraph demonstrating the use of CSS variables.</p>
</main>
<footer>
<p>© 2024 My Website</p>
</footer>
</body>
</html>
CSS Code
:root {
--main-bg-color: #f0f0f0;
--main-text-color: #333333;
--header-bg-color: #4CAF50;
--header-text-color: white;
--main-padding: 20px;
}
body {
background-color: var(--main-bg-color);
color: var(--main-text-color);
padding: var(--main-padding);
font-family: Arial, sans-serif;
}
header {
background-color: var(--header-bg-color);
color: var(--header-text-color);
padding: var(--main-padding);
text-align: center;
}
footer {
text-align: center;
padding: var(--main-padding);
}
Benefits of Using CSS Variables
- Maintainability: Easier to manage and update CSS values.
- Reusability: Use the same values in multiple places.
- Theming: Easily switch themes by changing the values of variables.
Advanced Usage
Fallback Values
color: var(--undefined-variable, #000000);
Local Scope
CSS variables can also be scoped to a specific element. This means they can be overridden in a specific context.
.card {
--card-bg-color: white;
--card-text-color: black;
background-color: var(--card-bg-color);
color: var(--card-text-color);
}
.card-dark {
--card-bg-color: #333333;
--card-text-color: #f0f0f0;
}
<div class="card">This is a card</div>
<div class="card card-dark">This is a dark card</div>
Conclusion
CSS variables are a powerful tool for making your CSS more flexible and easier to maintain. By using variables, you can ensure consistency across your stylesheets and make global changes with ease.
Some other post
- Learn best Web Animations with “CSS and GSAP Animation: Beginner to Advanced Journey” Course
- Build Your Own Personalized Newspaper Reader in Python Using NewsAPI
- Getting Started with best Code Editor Visual Studio Code: A Beginner’s Guide
- Understanding OpenCV: A Comprehensive Guide to Computer Vision with Python
- GSAP Unleashing the Power of Web Animations
164 Comments
fb accounts for sale buy facebook ad account
facebook ad accounts for sale buy fb ads account
facebook ads account buy cheap facebook advertising account
buy facebook accounts cheap buy facebook ad account
маркетплейс аккаунтов https://kupit-akkaunt.online
купить аккаунт https://akkaunty-dlya-prodazhi.pro/
магазин аккаунтов online-akkaunty-magazin.xyz
покупка аккаунтов маркетплейсов аккаунтов
маркетплейс аккаунтов https://kupit-akkaunty-market.xyz
canada pharmacy prednisone: prednisone 20 – PredniHealth
биржа аккаунтов akkaunty-market.live
маркетплейс аккаунтов https://akkaunt-magazin.online/
PredniHealth: can you buy prednisone over the counter in canada – fast shipping prednisone
get generic clomid without dr prescription: where can i get clomid now – can i buy cheap clomid tablets
биржа аккаунтов https://kupit-akkaunt.xyz
PredniHealth: PredniHealth – prednisone pill 20 mg
магазин аккаунтов https://rynok-akkauntov.top
маркетплейс аккаунтов https://akkaunty-na-prodazhu.pro/
account store https://accounts-marketplace-best.pro
Your comment is awaiting moderation.
generic tadalafil order Cialis online no prescription or affordable ED medication
http://flthk.com/en/productshow.asp?id=22&mnid=49487&mc=FLT-V1/V2&url=https://zipgenericmd.com reliable online pharmacy Cialis
affordable ED medication cheap Cialis online and cheap Cialis online order Cialis online no prescription
discreet shipping ED pills: buy generic Cialis online – discreet shipping ED pills
cheap Viagra online: secure checkout Viagra – no doctor visit required
secure checkout Viagra: safe online pharmacy – no doctor visit required
https://maxviagramd.shop/# cheap Viagra online
best price Cialis tablets: discreet shipping ED pills – discreet shipping ED pills
modafinil legality: modafinil legality – Modafinil for sale
Your comment is awaiting moderation.
cheap Cialis online discreet shipping ED pills or generic tadalafil
https://couponifier.com/store/zipgenericmd.com discreet shipping ED pills
affordable ED medication affordable ED medication and generic tadalafil affordable ED medication
Your comment is awaiting moderation.
order Cialis online no prescription order Cialis online no prescription or generic tadalafil
https://cse.google.mw/url?sa=t&url=https://zipgenericmd.com Cialis without prescription
Cialis without prescription online Cialis pharmacy and Cialis without prescription cheap Cialis online
http://modafinilmd.store/# verified Modafinil vendors
buy modafinil online: Modafinil for sale – safe modafinil purchase
trusted Viagra suppliers: legit Viagra online – trusted Viagra suppliers
http://modafinilmd.store/# verified Modafinil vendors
safe modafinil purchase: Modafinil for sale – verified Modafinil vendors
account exchange service https://social-accounts-marketplace.live
affordable ED medication: generic tadalafil – online Cialis pharmacy
Your comment is awaiting moderation.
secure checkout ED drugs affordable ED medication or FDA approved generic Cialis
http://forum.ssmd.com/proxy.php?link=https://zipgenericmd.com buy generic Cialis online
discreet shipping ED pills Cialis without prescription and reliable online pharmacy Cialis secure checkout ED drugs
account acquisition https://accounts-marketplace.online
https://maxviagramd.shop/# legit Viagra online
account selling platform https://buy-accounts.live
generic sildenafil 100mg: same-day Viagra shipping – trusted Viagra suppliers
account buying service account market
safe online pharmacy: discreet shipping – trusted Viagra suppliers
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Your comment is awaiting moderation.
best price Cialis tablets reliable online pharmacy Cialis or FDA approved generic Cialis
https://ultramar-ti.com/redirect/Index.asp?url=http://zipgenericmd.com order Cialis online no prescription
order Cialis online no prescription best price Cialis tablets and secure checkout ED drugs affordable ED medication
affordable ED medication: buy generic Cialis online – Cialis without prescription
verified accounts for sale https://buy-accounts.space/
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
verified Modafinil vendors: modafinil pharmacy – safe modafinil purchase
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
account trading platform account market
purchase ready-made accounts https://accounts-marketplace.live
accounts marketplace https://social-accounts-marketplaces.live
Your comment is awaiting moderation.
best price Cialis tablets generic tadalafil or affordable ED medication
https://www.google.co.ve/url?sa=t&url=https://zipgenericmd.com order Cialis online no prescription
generic tadalafil generic tadalafil and FDA approved generic Cialis affordable ED medication
modafinil legality: safe modafinil purchase – verified Modafinil vendors
modafinil 2025: modafinil pharmacy – Modafinil for sale
online account store https://accounts-marketplace.xyz/
buy and sell accounts accounts market
discreet shipping: trusted Viagra suppliers – no doctor visit required
secure checkout ED drugs: cheap Cialis online – online Cialis pharmacy
sell pre-made account account trading service
buy account guaranteed accounts
sell account account trading platform
secure account sales account selling platform
online account store purchase ready-made accounts
account trading account selling service
secure account sales account sale
Your comment is awaiting moderation.
pin up вход пин ап казино or пинап казино
http://localhoneyfinder.org/facebook.php?URL=https://pinuprus.pro pin up вход
=generic+cialis]пинап казино пин ап зеркало and пин ап казино пин ап казино
account selling service account buying platform
vavada: вавада официальный сайт – вавада официальный сайт
buy pre-made account verified accounts for sale
account buying service account catalog
vavada: vavada casino – вавада зеркало
Your comment is awaiting moderation.
пин ап вход пин ап казино официальный сайт or pin up вход
http://fishingkuban.ru/forum/away.php?s=http://pinuprus.pro pin up вход
пин ап казино официальный сайт пинап казино and пин ап зеркало пин ап казино официальный сайт
вавада зеркало: vavada – вавада казино
buy and sell accounts account exchange service
vavada: vavada вход – vavada вход
marketplace for ready-made accounts secure account purchasing platform
ready-made accounts for sale ready-made accounts for sale
buy accounts account selling platform
account trading find accounts for sale
account catalog sell account
account trading platform account trading platform
account buying service account exchange
account buying service website for selling accounts
pin up вход: пин ап вход – пинап казино
account selling platform accounts marketplace
account catalog account buying service
pin-up: pin up azerbaycan – pin up casino
pin up az: pin up az – pin-up casino giris
account selling service sell pre-made account
пинап казино: пин ап казино – pin up вход
sell pre-made account sell account
website for buying accounts account exchange
Your comment is awaiting moderation.
pinup az pinup az or pin up
http://henporai.net/acc/acc.cgi?REDIRECT=https://pinupaz.top pinup az
pin up az pinup az and pin up azerbaycan pin up az
pin up casino: pin-up casino giris – pin-up
вавада зеркало: вавада казино – vavada
Your comment is awaiting moderation.
pin up az pin up casino or pin up casino
https://parts.harnessmaster.com/index.php?category=Hardware and Terminal Studs&colour=Silver&part=463&rurl=https://pinupaz.top pin-up casino giris
pin up pinup az and pin-up casino giris pin up azerbaycan
Online Account Store Account Selling Service
вавада зеркало: вавада – vavada
Accounts for Sale Gaming account marketplace
Account Acquisition Ready-Made Accounts for Sale
vavada casino: vavada вход – vavada
Your comment is awaiting moderation.
pin up azerbaycan pin up az or pin up az
http://kreepost.com/go/?https://pinupaz.top pin-up
pin up casino pinup az and pinup az pin up casino
Accounts marketplace Verified Accounts for Sale
пин ап зеркало: пин ап казино – пин ап казино официальный сайт
Secure Account Purchasing Platform Account Sale
Buy Pre-made Account Accounts marketplace
Your comment is awaiting moderation.
pin-up casino giris pin up casino or pinup az
https://kultameren.fi/pennut/gotourl.php?url=http://pinupaz.top pinup az
pinup az pin up casino and pin up casino pin-up
vavada вход: vavada вход – вавада
пин ап казино официальный сайт: пин ап вход – пин ап вход
Account trading platform Website for Buying Accounts
Your comment is awaiting moderation.
pin up azerbaycan pin up az or pin up
https://www.google.im/url?q=https://pinupaz.top pin up casino
pin-up casino giris pin up and pinup az pin-up
pin-up: pin up az – pin up azerbaycan
Account market Gaming account marketplace
Secure Account Sales Account Exchange Service
Account Sale Guaranteed Accounts
pinup az: pin-up casino giris – pin up casino
Your comment is awaiting moderation.
pin-up casino giris pin-up or pin up azerbaycan
http://www.mn2020.org/?URL=pinupaz.top pin-up
pin up azerbaycan pin up az and pin up casino pin up
pin up casino: pin-up casino giris – pin up casino
вавада: вавада официальный сайт – вавада зеркало
Your comment is awaiting moderation.
pin up azerbaycan pin-up casino giris or pin up azerbaycan
http://cybermann.com/main.php?g2_view=core.UserAdmin&g2_subView=core.UserRecoverPassword&g2_return=https://pinupaz.top pinup az
pin up azerbaycan pin up azerbaycan and pin up pin-up casino giris
продажа аккаунтов магазин аккаунтов социальных сетей
маркетплейс аккаунтов гарантия при продаже аккаунтов
пин ап казино: пинап казино – pin up вход
продажа аккаунтов соцсетей купить аккаунт с прокачкой
магазин аккаунтов маркетплейс аккаунтов соцсетей
пин ап зеркало: пин ап вход – pin up вход
Your comment is awaiting moderation.
pin-up casino giris pin up or pin up
https://maps.google.si/url?sa=t&url=https://pinupaz.top pin-up
pin up azerbaycan pin up casino and pin up azerbaycan pin-up casino giris
пин ап зеркало: пин ап казино – пин ап казино официальный сайт
продажа аккаунтов соцсетей аккаунт для рекламы
вавада официальный сайт: вавада зеркало – vavada
маркетплейс аккаунтов соцсетей https://birzha-akkauntov-online.ru
Your comment is awaiting moderation.
pinup az pin up az or pin-up casino giris
http://www.ra2.od.ua/engine/redirect.php?url=http://pinupaz.top pin up
pinup az pin-up and pin up az pin up azerbaycan
пинап казино: pin up вход – пин ап казино
пинап казино: pin up вход – пин ап вход
Your comment is awaiting moderation.
pin up pinup az or pin-up casino giris
http://www.c9wiki.com/link.php?url=http://pinupaz.top/ pin up azerbaycan
pin up casino pin-up and pin up azerbaycan pin up azerbaycan
пин ап зеркало: pin up вход – пин ап казино официальный сайт
medicine courier from India to USA: MedicineFromIndia – indian pharmacy online
Your comment is awaiting moderation.
india pharmacy indian pharmacies safe or top 10 pharmacies in india
https://maps.google.com.tw/url?q=https://medicinefromindia.com online shopping pharmacy india
Online medicine home delivery online shopping pharmacy india and pharmacy website india online shopping pharmacy india
buy medicines online in india Medicine From India indian pharmacy online shopping
buying prescription drugs in mexico online: mexico pharmacy order online – mexico drug stores pharmacies
medicine courier from India to USA: indian pharmacy – indian pharmacy online shopping
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
trustworthy canadian pharmacy Buy medicine from Canada canadian pharmacy meds
mexican rx online: mexican online pharmacy – mexican online pharmacy
canadian family pharmacy: Express Rx Canada – vipps approved canadian online pharmacy
Your comment is awaiting moderation.
indian pharmacies safe indian pharmacy online or Online medicine order
https://images.google.nr/url?q=https://medicinefromindia.com top 10 pharmacies in india
п»їlegitimate online pharmacies india top 10 online pharmacy in india and cheapest online pharmacy india online pharmacy india
indian pharmacy: indian pharmacy online shopping – MedicineFromIndia
mexico drug stores pharmacies mexican rx online Rx Express Mexico
best online pharmacy india: Medicine From India – indian pharmacy
mexico drug stores pharmacies: mexican rx online – mexico pharmacy order online
mexican rx online mexico pharmacies prescription drugs Rx Express Mexico
Rx Express Mexico: Rx Express Mexico – mexico drug stores pharmacies
Your comment is awaiting moderation.
indian pharmacies safe indian pharmacies safe or top 10 pharmacies in india
http://www.lifeact.jp/mt/mt4i.cgi?id=1&cat=1&mode=redirect&no=1&ref_eid=1698&url=http://medicinefromindia.com top 10 online pharmacy in india
indian pharmacies safe top 10 online pharmacy in india and buy prescription drugs from india indian pharmacy online
Your comment is awaiting moderation.
indian pharmacy paypal indian pharmacy or cheapest online pharmacy india
https://siamloaning.com/redirect.php?blog=B8A1B89AB895B8%A3B894B999B89420PROUD&url=https://medicinefromindia.com mail order pharmacy india
indianpharmacy com online pharmacy india and mail order pharmacy india indian pharmacy paypal
Medicine From India: indian pharmacy – medicine courier from India to USA
reliable canadian pharmacy: Express Rx Canada – canadian pharmacy
canada pharmacy world: Buy medicine from Canada – canadian pharmacy 24h com safe
Medicine From India: MedicineFromIndia – MedicineFromIndia
Pharmacie en ligne Cialis sans ordonnance: Achat Cialis en ligne fiable – Tadalafil achat en ligne tadalmed.shop
pharmacie en ligne pas cher: Livraison rapide – acheter mГ©dicament en ligne sans ordonnance pharmafst.com
kamagra gel: Kamagra Oral Jelly pas cher – kamagra en ligne
Acheter Cialis: Tadalafil sans ordonnance en ligne – Pharmacie en ligne Cialis sans ordonnance tadalmed.shop
pharmacie en ligne france pas cher: pharmacie en ligne pas cher – pharmacie en ligne pharmafst.com
Tadalafil achat en ligne: Tadalafil achat en ligne – cialis prix tadalmed.shop
kamagra en ligne: kamagra oral jelly – Acheter Kamagra site fiable
kamagra 100mg prix: Kamagra pharmacie en ligne – kamagra gel
cialis sans ordonnance: Pharmacie en ligne Cialis sans ordonnance – Achat Cialis en ligne fiable tadalmed.shop
Your comment is awaiting moderation.
Kamagra pharmacie en ligne kamagra gel or kamagra oral jelly
https://www.google.hr/url?q=https://kamagraprix.shop Achetez vos kamagra medicaments
Achetez vos kamagra medicaments kamagra gel and kamagra en ligne acheter kamagra site fiable
Acheter Kamagra site fiable: kamagra pas cher – Kamagra Commander maintenant
acheter kamagra site fiable: Achetez vos kamagra medicaments – acheter kamagra site fiable
Kamagra Commander maintenant: kamagra oral jelly – Acheter Kamagra site fiable
Pharmacie sans ordonnance: pharmacie en ligne sans ordonnance – Achat mГ©dicament en ligne fiable pharmafst.com
Your comment is awaiting moderation.
Acheter Kamagra site fiable kamagra oral jelly or acheter kamagra site fiable
https://cse.google.com.ng/url?sa=t&url=https://kamagraprix.shop kamagra livraison 24h
[url=https://www.google.com.sv/url?q=https://kamagraprix.shop]kamagra gel[/url] kamagra pas cher and [url=https://www.soumoli.com/home.php?mod=space&uid=183311]Kamagra pharmacie en ligne[/url] Acheter Kamagra site fiable
Your comment is awaiting moderation.
pharmacies en ligne certifiГ©es trouver un mГ©dicament en pharmacie or pharmacie en ligne pas cher
https://secure.aos.org/login.aspx?returnurl=http://pharmafst.com/ pharmacie en ligne livraison europe
acheter mГ©dicament en ligne sans ordonnance pharmacie en ligne avec ordonnance and pharmacie en ligne avec ordonnance pharmacies en ligne certifiГ©es
pharmacie en ligne sans ordonnance: Pharmacie en ligne France – п»їpharmacie en ligne france pharmafst.com
Your comment is awaiting moderation.
kamagra gel kamagra oral jelly or kamagra pas cher
http://www.marstruct-vi.com/feedback.aspx?page=http://kamagraprix.shop/ achat kamagra
achat kamagra kamagra oral jelly and kamagra oral jelly kamagra gel
Cialis en ligne: cialis sans ordonnance – cialis prix tadalmed.shop
kamagra pas cher: kamagra en ligne – kamagra en ligne
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Your article helped me a lot, is there any more related content? Thanks!
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me. https://accounts.binance.info/register?ref=P9L9FQKY
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you. https://www.binance.info/join?ref=P9L9FQKY
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
[…] if you want to gain knowledge about CSS variable then click […]