CKTIS / HTML
The style element — an embedded CSS stylesheet
The `style` element embeds a CSS stylesheet in an HTML document. It contains rules with selectors, not page content. It is different from the `style` attribute on an individual element.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
<style media="all">
selector { property: value; }
</style>The style element contains stylesheet text, usually in head. Both tags are required. Unlike the style attribute, which contains declarations for one element, a stylesheet uses selectors to target elements.
The media attribute restricts application to matching conditions; its default is all. Omit type: the embedded language is CSS. A Content Security Policy can block the stylesheet.
The current standard also permits style as its parent's first child where flow content is expected. Inside body, however, it prohibits @import and requires ordinary rules to be enclosed in a block such as @scope { ... }, whose scoping root is the parent. For a simple document stylesheet, use head.
In the example, .notice gives the paragraph the color rgb(0, 64, 128). The stylesheet itself is not visible page content.
Examples
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Style demo</title>
<style>
.notice { color: rgb(0, 64, 128); }
</style>
</head>
<body>
<p class="notice">CSS works.</p>
</body>
</html>Result
CSS works.
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.