Many websites on the internet are available in multiple themes. One can obtain any feature by making multiple stylesheets into the HTML code and enabling one at a time. A CSS file is included into the HTML in the <head> tag using the <link> tag.
<link id="theme" rel="stylesheet" type="text/css" href="light.css" />
The “href” attribute specifies the file location of the CSS file. By altering this tag, we can add new CSS to the website. The implementation can be done using any of the following methods.
Method 1: When you want to make a switch or toggle button, to toggle the CSS. It switches between the values depending upon the currently active value.
On clicking the switch button:
Method 2: When you want to select from multiple style sheets. The value for the “href” attribute is passed to the function call itself.
Prerequisite: Prepare all the style sheets in a folder.
Note: The corresponding CSS files with required names should be available and the path to them should be passed using the function. The files specified here are placed in the same folder of the HTML file so that the path resembles ‘light.css’.
Attention reader! Don’t stop learning now. Get hold of all the important Comcompetitivepetitve Programming concepts with the Web Design for Beginners | HTML course.