CSS var() फ़ंक्शन कस्टम प्रॉपर्टी (CSS वेरिएबल) के मान को डालने के लिए उपयोग किया जाता है। :root में कस्टम प्रॉपर्टी परिभाषित करें और फिर var(--name) से उपयोग करें।
उदाहरण
<!DOCTYPE html> <html> <head> <style> :root { --my-bg-color: blue; --my-color: white; } #demo { background-color: var(--my-bg-color); color: var(--my-color); } </style> </head> <body> <h1>Heading One</h1> <div id = "demo"> This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. </div> <br> </body> </html>
व्याख्या: :root में --my-bg-color और --my-color परिभाषित हैं। #demo में var() से उनका उपयोग किया गया है, जिससे थीम बदलना आसान हो जाता है।