How to let user change CSS? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to let user change CSS?

Is there a way to implement a form that lets a user change some CSS of a website. So for example, let the user change a colour theme by selecting from a list of themes? Or change the font size or font type?

24th Apr 2020, 3:47 PM
MBanski
MBanski - avatar
2 Answers
+ 1
Yes, by javascript In my code you can change background color https://code.sololearn.com/WX195IlYDnkg/?ref=app
24th Apr 2020, 3:50 PM
🇮🇳Vivek🇮🇳
🇮🇳Vivek🇮🇳 - avatar
+ 1
Create different stylesheets e.g. screen-default.css, screen-dark-mode.css, print-default.css etc. ____________________ Method 1 Give the <link rel="stylesheet"> an ID and edit the id attribute with javascript. ____________________ Method 2 With javascript, Apply a class to the <html> tag e.g <html lang="en" class="dark-mode"> Then in your css add custom styles like this .dark-mode elem{ //dark mode style override } __________________ Method 3 Use a hash after the url that says something like http://url.....#dark Then use window.location.hash function to get the hash string. Apply styling based on method 1 or method 2 _________________ Method 4 - Server side solution Save the theme with a cookie in the user browser. When the site loads request the cookie and serve the right style based on tge value of the cookie
24th Apr 2020, 4:13 PM
Ore
Ore - avatar