Table of Contents
INTRODUCTION
The <style> element is used to add Internal CSS. It is included in the <head> section of webpage. Its scope is limited to single page in which it is included, hence has to be written in each HTML page. It is mostly used to style single webpage or small sites.
Multiple <style> elements can be declared within one webpage. In case of overlapping rules, the general rules of specifity, cascade and order are used to decide which CSS rule is applied.
Syntax:
<style>
HTML Selector{
CSS rules
}
</style>
Example:
<style>
p{
font-size:1rem;
}
</style>
Attributes
1. media
This attribute specifies which media the style applies to. Its value is a media-query. The default value of this attribute is all.
Example:
<style media="print">
p{
font-size:1rem;
}
</style>
2. title
This attribute specifies an alternate style sheet.
3. type
This attribute is deprecated and should not be used. If it is used the only permitted values are empty string and text/css
Tag Omission
The HTML <style> element must have both start tag and end tag.
Frequently Asked Questions (FAQ)
How to Add the <style> Element in HTML?
Can You Use <style> Tags Inside <body>?
What is the Difference Between <style> Tag and style Attribute in HTML?
The <style> tag is used to define CSS rules for multiple elements within an HTML document.
The style attribute applies CSS directly to a single element.