Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define global variables in css

Tags:

html

css

I want to define global variables in one css file and use the variables in other css files.

Is this possible?

Global.css:

:root {
    --main-color: #192100;
    --main-background: #89b66b;
}

html, body {
    min-height: 100%;
    width: 100%;
    font-family: Arial;
    color: var(--main-color);
}

SomeFile.css:

.some-rule {
    display: table;
    border-radius: 12px;
    border: 4px solid var(--main-color);
    padding-left: 10px;
    padding-right: 10px;
    color: var(--main-color);
}

Html: (Global.css if referenced before SomeFile.css)

<link href="Global.css" rel="stylesheet" type="text/css" />
<link href="SomeFile.css" rel="stylesheet" type="text/css" />
like image 771
SteinTheRuler Avatar asked Nov 22 '25 15:11

SteinTheRuler


1 Answers

You can't do that with CSS. Try A CSS Preprocessor like Less or Sass.

less.css sharing variables across files

SASS - use variables across multiple files

like image 184
Reza Ramezanpour Avatar answered Nov 25 '25 09:11

Reza Ramezanpour



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!