HTML style tag

What is the purpose of the HTML style tag?

You can use style tag for including CSS in your webpage. Style tag must reside within <​head></head> tags of your webpage. Through style tag you can define page level CSS in your webpage. CSS makes it easy to enhance your webpage’s appearance and create an attractive, well-designed layout. Example


type="text/CSS"
Optional Attributes
Attribute Value Description DTD
media screen
tty
tv
projection
handheld
print
braille
aural
all
It provides styles for different media types STF
Standard Attributes

The style tag supports the following standard attributes:
Attribute Value Description DTD
dir rtl
ltr
Specifies the text direction for the content in an element STF
lang language_code Specifies a language code for the content in an element STF
title text Specifies extra information about an element STF
Example

<​style>
body {
  color: red;
  background-color: yellow;
  font-size: 80%;
}

p {
  line-height: 1.5em;
}
</style>

FAQ 1. Can an HTML page have multiple style tags? Yes. An HTML document can contain multiple style elements. However, organizing related CSS rules into a single style block or using external stylesheets can make code easier to maintain. 2. Is the HTML style tag used for internal or external CSS? The HTML style tag is used for internal CSS, also known as embedded CSS. External CSS is included using the link tag, which references a separate CSS file.