3

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" />
SteinTheRuler
  • 3,549
  • 4
  • 35
  • 71

2 Answers2

1

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

Reza Ramezanpour
  • 585
  • 8
  • 28
0

CSS itself doesn't use variables. However, you can use another language like SASS or LESS

Dmitry B.
  • 426
  • 4
  • 11