👀 Live Preview
Heading styled with embedded CSS rules:

The <style> tag lets you write CSS directly inside an HTML document. This guide covers head placement, syntax, attributes, global and element-specific rules, and when to use external stylesheets instead.
Write rules inside style in the head.
Load styles before body content renders.
Fonts, colors, and page backgrounds.
Target h1, p, and more.
Know internal, external, and inline CSS.
Organize CSS and prefer external files.
<style> Tag?The <style> tag is an HTML element that lets you embed CSS (Cascading Style Sheets) directly within an HTML document. It empowers developers to apply colors, fonts, spacing, and layout rules to HTML elements without a separate stylesheet file.
The style tag holds CSS rules in the head. The style attribute on an element applies CSS to one tag only. They are different techniques.
Use embedded CSS for page-specific styles, quick prototypes, or critical above-the-fold styling. For shared styles across many pages, prefer external CSS via <link>.
Place style inside the document’s head and wrap your CSS rules between opening and closing tags:
<!DOCTYPE html>
<html lang="en">
<head>
<style>
/* Your CSS rules go here */
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
}
</style>
</head>
<body>
<!-- Your HTML content here -->
</body>
</html>style inside head for best practice (body placement is allowed but discouraged).<style />) is not valid in HTML./* ... */) to document your rules.| Topic | Code Snippet | Notes |
|---|---|---|
| Basic style block | <style>...</style> | In head |
| Element rule | h1 { color: blue; } | Selector + declarations |
| Legacy type | type="text/css" | Optional in HTML5 |
| Media query | media="screen" | Conditional styles |
| vs external CSS | <link rel="stylesheet"> | Shared across pages |
| Browser support | Universal | All browsers |
<style> vs <link> vs Inline style| Approach | Location | Best for |
|---|---|---|
<style> tag | CSS rules in head | Page-specific or critical CSS |
<link rel="stylesheet"> | External .css file | Shared styles, production sites |
style attribute | On a single element | One-off tweaks (use sparingly) |
The <style> tag has few attributes. In HTML5, CSS is the default style language and type is optional.
<style type="text/css">
h1 {
color: #3498db;
}
</style>type OptionalDeclares the style language. text/css is default in HTML5 — attribute can be omitted.
type="text/css"media OptionalLimits styles to a media type or query, e.g. screen or (max-width: 768px).
media="screen"title OptionalNames an alternate stylesheet when multiple style blocks exist.
title="Alternate"blocked AdvancedPrevents the stylesheet from applying until removed via script (rare use).
blockedElement-specific rules, global document styles, and complete head placement with copy-ready code and live previews.
Heading styled with embedded CSS rules:
Use <style> for global document styles, element-specific rules, and page-unique CSS that does not belong in a shared external file.
Apply styles to specific HTML elements such as headings to create a tailored look:
<style>
h1 {
color: #2ecc71;
text-align: center;
}
</style>The style tag is ideal for defining global styles that apply to the entire document, including fonts and backgrounds:
<style>
body {
font-family: 'Roboto', sans-serif;
background-color: #f8f8f8;
}
</style>Full document structure with style in the head section:
<head>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
}
</style>
</head>display: none on important information users need.prefers-reduced-motion and scalable font sizes.:focus-visible styles for keyboard users.Rules are placed inside a style element.
The engine reads selectors and declarations before rendering body content.
Matching HTML elements receive the declared colors, fonts, and layout.
Visual presentation is controlled without changing HTML structure.
The <style> tag is supported in all major browsers, including Internet Explorer.
All browsers parse and apply <style> blocks in the document head.
Bottom line: Use <style> confidently to embed CSS in any browser.
The <style> tag transforms the visual aesthetics of HTML documents. Whether applying global styles or fine-tuning specific elements, understanding embedded CSS is key to creating stylish, user-friendly web pages.
style blocksstyle in the head for early style applicationstyle tag with the inline style attributelink<style>Bookmark these before you embed CSS in your pages.
Internal styles.
PurposeBest placement.
LocationPage-wide CSS.
Use caseExternal CSS.
ComparisonAttributes.
ReferenceAll browsers.
Compatibilityhead, to style page elements.head element. CSS rules between the tags apply to the document.style tag holds CSS for many selectors. The style attribute styles one element only.type="text/css" is optional legacy syntax.Practice <style> for global and element-specific rules in the Try It editor.
6 people found this page helpful