Document Metadata
HTML <style> element
Embeds CSS rules in the document. Selectors and declarations inside it are CSS, not HTML attributes. The style element is normally metadata in head. It contains a stylesheet rather than a style attribute declaration list. Use external stylesheets for shared rules; a Content Security Policy can restrict embedded CSS. It accepts global HTML attributes; individual global features may be inapplicable or restricted.
Formal Syntax & Structure
html syntaxhtml
<style>p { color: navy; }</style>Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| media | media query list | Specifies conditions under which a resource or metadata applies, such as a stylesheet's target media or a picture source's viewport condition. |
| blocking | space-separated tokens | Requests eligible resource processing to block rendering; render is the relevant token. This can delay visible content, so use only when needed. |
| nonce | server-generated unpredictable token | Matches a CSP nonce source to authorize an eligible script or style. Generate a fresh unpredictable value per response; never reuse a fixed example nonce in production. |
Return Value
HTMLStyleElement
Content model: Text governed by the applicable style or script language; no ordinary HTML child elements.
Working Example
Example Snippethtml
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <title>Example</title> <style>p { color: navy; }</style> </head> <body> <p>Reading notes</p> </body></html>