---
title: "How to create a \"style\" tag with Javascript?"  
description: "How to create a \"style\" tag with Javascript?"  
author: "Utpal Vishwas"  
published: 2023-04-30  
updated: 2023-05-01  
canonical: https://www.mindstick.com/forum/158100/how-to-create-a-style-tag-with-javascript  
category: "javascript"  
tags: ["jquery", "javascript", "html"]  
reading_time: 1 minute  

---

# How to create a "style" tag with Javascript?

How to create a <[style](https://www.mindstick.com/articles/126300/apa-citation-style-get-to-know-about-it-for-your-next-assignment)> tag with [Javascript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript)?

## Replies

### Reply by Aryan Kumar

To 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:

```javascript
// create a new style element
var styleTag = document.createElement('style');
// add some CSS rules to the style element
styleTag.innerHTML = `
 body {
   background-color: yellow;
 }
 h1 {
   color: blue;
   font-size: 24px;
 }
`;
// append the style element to the head of the document
document.head.appendChild(styleTag);
```

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.

\


---

Original Source: https://www.mindstick.com/forum/158100/how-to-create-a-style-tag-with-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
