Skip to the page
html reference · other

HTML <style> tag

closing tag
required
void element
no
lives inside
<head>
typically holds
CSS rules — selectors and declaration blocks

Where it goes

Inside <head>, before the content it styles. Once styles are shared across pages, move them to a .css file and attach it with <link>.

Example

<head>
  <style>
    h1 { color: teal; }
    p { line-height: 1.6; }
  </style>
</head>

Open this example in the editor →

Common mistakes

  • Writing HTML tags inside it. <style> switches the browser into CSS mode, so <h1> in there is an error. Write a plain h1 selector instead.
  • Forgetting the closing </style>. The browser keeps reading the rest of the page as CSS, and the page goes blank.
  • Mixing it up with the style="" attribute. <style> is a block of rules in <head>. style="color: red" is one rule on one tag, and it beats the block.

Related

Updated 24 October 2026. Practice it in the html route, or read more on MDN.