How to create a <style> tag with Javascript?
How to create a "style" tag with Javascript?
443
30-Apr-2023
Updated on 01-May-2023
Aryan Kumar
01-May-2023To create a style tag with JavaScript, you can use the createElement() method to create the style element and then append it to the head element of the document using the appendChild() method.
Here's an example code snippet:
In this example, we create a style element using createElement(), add some CSS rules using the innerHTML property, and then append it to the head of the document using appendChild(). This will add the CSS rules to the document and apply them to the relevant elements.