0

Is there a way to make CSS dynamic? I want to set a variable in the CSS file. Something like this:

var baseColour = #000; 
body{
  background-colour: baseColour;
}

I want to let the user choose a colour. Then I want to set the variable in CSS to the user input with JavaScript.

Is that possible? Or at least that one with the variable?

4
  • 3
    Use a CSS preprocesor, for example Sass. Commented Jan 16, 2016 at 19:33
  • Look at less or sass Commented Jan 16, 2016 at 19:34
  • You can make CSS dynamic with javascript, php, asp... Commented Jan 16, 2016 at 19:40
  • as a choice of user, you might have to use cookies to keep the setup through page visited Commented Jan 16, 2016 at 19:44

1 Answer 1

2

No CSS can't do this by default, you may want to use SASS for something like this.

Sign up to request clarification or add additional context in comments.

2 Comments

This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
I think it's the most simple and direct answer to his main question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.