<style>...</style>

HTML4 HTML5

The <style> tag is used to embed CSS rules directly inside an HTML document (internal styles)[cite: 3]. It allows styling page elements like colors, fonts, layouts, and spacing without separate CSS files[cite: 3].

It is most commonly placed in the <head> section, though HTML5 permits usage inside <body>[cite: 3].

Both opening and closing tags are mandatory[cite: 3].

Attributes:

Example

In the example below, the <style> tag defines heading and paragraph styling using CSS rules[cite: 3]:

Code:

<style>
.custom-heading {
   color: darkblue;
   font-size: 1.2em;
}
.highlight-box {
   background-color: #e6f7ff;
   padding: 8px;
   border-left: 4px solid #1890ff;
}
</style>
<h3 class="custom-heading">Styled Heading</h3>
<p class="highlight-box">This is a paragraph with custom background and left border.</p>

The browser will interpret this code as follows:

Styled Heading

This is a paragraph with custom background and left border.