HTML5 <style> Tag

The HTML <style> tag contains style information for a document, or part of a document. By default, the style instructions written inside this element are expected to be CSS.

The only content permitted inside this element is text content matching the type attribute, that is text/css. Both the start and end tag are mandatory for this element. The parent of the <style> tag can be any element that accepts metadata content.

The following style is applied to this element by default:

style {
  display: none;
}

Here is an example of using this tag:

<style>
  body {
    color:red;
    font-size: 1.25em;
  }
</style>

Attributes

type

This attribute defines the styling language as a MIME type (charset should not be specified). This attribute is optional and default to text/css if it’s missing.

media

This attribute defines which media the style should apply to. It’s value is a media query, which default to all if the attribute is missing.

title

Specifies alternative style sheet sets.

Further Reading

  1. Read more about the HTML <style> element on MDN.
  2. You can also read the HTML <style> tag reference on W3C.

Reader Comments

1. You can register or login to post a comment. Asking readers to register improves the quality of discussion.

2. As a registered user, you will also get to access features like choosing between a light and dark theme or anything else that we might implement in future.

Follow Us For Updates

FacebookTwitterGoogle+
Go To Top