Tag <style> In HTML
In this article, we’ll talk about Tag style with examples. Wishing it would satisfy the requirements for learning.
The <style> tag is an HTML element used to define styles for a web page. It is typically used in conjunction with cascading style sheets (CSS) to apply visual styling to HTML elements.
The <style> tag is utilized to specify a document’s style details (CSS). The <style> tag can be utilized to indicate what HTML elements should display in browsers.
Simple HTML document with the <style> tag:
Example: 
Creating a hover effect on a button:
Example: 
Another example is to create a media query to change the layout of a webpage based on the screen size:
Example: 
Using the <style> tag in HTML to create a unique element on a webpage is to create a CSS animation:
Example: 
Tag <Style> Uses
Here are some common uses of the <style> tag:
- The <style> tag is commonly used to define CSS rules that apply to specific HTML elements. For example, you could use the <style> tag to change the font color and size of all the headings in your document.
- The <style> tag can also be used to define an internal stylesheet. This is a way to include CSS rules directly within the HTML document, instead of linking to an external stylesheet.
- The <style> tag can also be used to define inline styles. This means that the style rules are applied directly to the HTML elements within the document.
- The <style> tag can be used to define media queries, which are CSS rules that only apply under certain conditions (such as screen size or orientation).
Advice:
- Links to external style sheets are created with the <link> tag.
- Our upcoming CSS tutorial will help you learn all about style sheets.
If you want to make a user attractive animation follow the example below:
Example: 
Attributes
Global
Tag <style> work with HTML’s Global Attributes too.
Event
The style tag <style> handles the HTML Event Attributes.
Attributes List
Attribute | Value | Overview |
---|---|---|
media | media_query | Indicates the media/device for which the media resource is adapted |
type | text/css | Sets the media type for the <style> tag |
Browser Compatibility
Element | |||||
---|---|---|---|---|---|
<style> | Yes | Yes | Yes | Yes | Yes |
Predefined CSS
The <style> element will be presented in majority of the browsers with these default values:
style { display: none; }
HTML Styles Tag Advantages
The <style> tag in HTML provides several advantages, including:
- The <style> tag allows you to define styles for your web page in a centralized location, rather than repeating the same styles for each individual HTML element. This can help simplify your code and make it easier to maintain over time. Additionally, by using CSS to define your styles, you can create more advanced and dynamic styling effects than you can with HTML alone.
- By using the <style> tag to define your styles in a separate file or section of your HTML document, you can reduce the amount of code that needs to be loaded by the browser. This can improve site performance and make your pages load faster.
- By using CSS to define your styles, you can separate the visual presentation of your content from the underlying HTML structure. This can help improve the accessibility of your site, as assistive technologies like screen readers can more easily parse the content and convey it to users with disabilities.
- By using the <style> tag to define your styles in a centralized location, you can ensure that all of your HTML elements are styled consistently across your site. This can help create a cohesive and professional-looking website that is easy for users to navigate and understand.