- HTML Tutorial
- HTML - Home
- HTML - Introduction
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Headings
- HTML - Paragraphs
- HTML - Fonts
- HTML - Blocks
- HTML - Style Sheet
- HTML - Formatting
- HTML - Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - <style> tag
HTML <style> tag contains style information for an HTML document or part of a document. This includes CSS (Cascading Style Sheets), which is applied to the content of an HTML document containing a <style> tag.
The <style> tag is used to declare the style sheets within the head element for the HTML document. We can have multiple style elements in a single head element. Generally, CSS is of three types, and if we use the style element inside the head element, then this CSS is known as internal CSS.
Syntax
<style>.....</style>
Attribute
HTML style tag supports Global and Event attributes of HTML. Accept some specific attributes as well which are listed below.
Attribute | Value | Description |
---|---|---|
media | media_query | Specifies what media/device the media resource is optimized for. |
type | text/css | Specify the media type. |
Examples of HTML style Tag
Bellow examples will illustrate the usage of style tag. Where, when and how to use style tag to style your html document.
Styling html document using style Tag
In the following program, we are using the HTML <style> tag to apply a simple stylesheet(CSS) to the HTML documents.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML style Tag</title> <style> h1 { color: green; font-size: 40px; font-style: italic; } </style> </head> <body> <h1>Text within h1 tag</h1> </body> </html>
Adding multiple Style Tag
The following is another example of the HTML <style> tag. Here, we're including two <style> tags to the applied stylesheet on the HTML document, and see how conflicting declarations in the later style element override the earlier one, if they have the same specificity.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML style Tag</title> <style> p { color: rgb(17, 114, 217); font-size: 40px; font-style: italic; font-weight: bolder; } </style> <style> p { color: red; font-size: 35px; font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif; } </style> </head> <body> <p>Text within p tag</p> </body> </html>
Meadia Query using style Tag
In this example, we are using the media(i.e. media query) attribute with the second "style" element. So it is only applied on the HTML document when the viewport(screen size) is less than 500px in width.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML style Tag</title> <style> h3 { color: red; font-size: 25px; font-style: italic; } </style> <style media="all and (max-width: 500px)"> h3 { color: green; font-size: 30px; font-weight: bolder; font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif; } </style> </head> <body> <h3>This is the 'h3' HTML element.</h3> </body> </html>
Supported Browsers
Tag | |||||
---|---|---|---|---|---|
style | Yes | Yes | Yes | Yes | Yes |