style – styles in the page
<style>…CSS…</style>
CSS styles written directly in the page. Useful for a small amount of styles the page needs straight away (critical styles) or for styles of a single page. Styles shared by the whole website belong in a file loaded via link – the browser stores it in its cache.
- Default display:
display: none - End tag: required
- Content: CSS text (tags inside are not treated as HTML)
- Where it can be used:
head(browsers also applystylein the body of the page, but according to the specification it does not belong there) - DOM interface:
HTMLStyleElement
Attributes
- media – the styles apply only to the given medium or condition (
print,(max-width: 600px)). - nonce – a one-time code with which Content Security Policy allows exactly this block of styles.
- title – the name of an alternative style sheet.
type="text/css"is the default and does not have to be written.
Examples
Styles in the head and separate styles for printing:
<style>
body { margin: 0; font-family: system-ui, sans-serif; }
.notice { padding: 8px 12px; background: #fff3cd; }
</style>
<style media="print">
nav, footer { display: none; }
</style>
Things to watch out for
- Styles in
styleare downloaded again with every page. For the styles of the whole website a file vialinkis better. - A Content Security Policy with
style-srcwithout'unsafe-inline'blocksstyleblocks without the correctnonce. - Browsers apply
stylein the body of the page, but the validator reports it as an error and the page may briefly appear without these styles. - Mind the order: a later rule with the same specificity overrides an earlier one – a style in the head after
linkoverrides the styles from the file.
Browser support
Baseline – widely available: works in all major browsers and has for a long time (since 2015 at the latest). Since version: Chrome 1, Firefox 1, Safari 1. As of October 2026 (MDN browser-compat-data).
Related:
link – linked resources
head – document head
style – inline style (attribute)
class – classes (attribute)