HTML <style> Tag Tutorial - Usage, Syntax, Attributes and Example

calender-iconPublished: 11 May 2025

clock-icon5-min read





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?
You can include a <style> block inside the <head> of your HTML file: This element is used to add CSS (Cascading Style Sheets) inside an HTML document to style elements like text, colors, layouts, and more.

Can You Use <style> Tags Inside <body>?
Yes, you can use <style> tags inside the <body>, but it's not recommended. The best practice is to place <style> inside <head> or use an external CSS file.

What is the Difference Between <style> Tag and style Attribute in HTML?
Both the <style> tag and style attribute allow you to apply CSS to HTML elements, but they work differently in terms of scope, maintainability, and best practices.
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.