Encodera

Thanks for reading!

Donate to the site — we work hard for you.

HTML & CSS reference

<style>

Embeds CSS right into the HTML page.

Syntax

<style> selector { property: value; } </style>

Attributes

ParameterTypeDescription
mediamedia queryOptional. Which screens the styles apply to.

Examples

Styles inside the page:

<style>
  h2 { color: teal; }
  .note { background: lightyellow; padding: 8px; }
</style>
 
<h2>Opening hours</h2>
<p class="note">Open daily from 8 am to 9 pm.</p>

Notes

Usually <style> goes into <head>. Embedded styles are handy for a single page and for examples, but for a site it is better to move CSS into a separate file and connect it with <link> — then every page can use it.

See also

  • <link> — Links an external resource to the page: a stylesheet, the site icon, a font.
  • style — CSS properties right on the element (inline styles).
  • <head> — The service part of the page: encoding, tab title, linked styles and scripts.

Related recipes

In the tutorial

  • What is CSS — How a CSS rule works, where to write styles, how to attach a separate file and why comments are useful.

Thanks for reading!

Donate to the site — we work hard for you.