- 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 Attribute
HTML style attribute contains a CSS styling declaration and is used to apply it to an element.
This is a global attribute, and it is recommended to define styles in a separate files. The style attribute and the <style> element have the same purpose, to allow quick styling.
If the style attribute is used inside any element for styling, you can call it inline CSS.
Syntax
<element style="property:value;">
Applies on
Since style is a global attribute, it applies to all the elements, though it may have no effect on some elements(Tags placed inside of head element).
Examples of HTML style Attribute
Bellow examples will illustrate the HTML style attribute, where and how we should use this attribute!
Inline styling using style Attribute
In the following example we have create two elements h1 and p and applied styling on both of them.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML style attribute</title> </head> <body> <!-- Example of style attribute--> <h1> <span style="color: green;">Tutorials</span>point </h1> <p style="margin-top: -20px; margin-left: 100px"> Simply Easy Learning </p> </body> </html>
Overriding internal CSS using style attribute
Internal css is the most prioritize css, if we applied CSS on any element and use style attribute on that element to change the style, it will prioritize the inline css.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML style attribute</title> <style> span{ color: black; } </style> </head> <body> <!-- Example of style attribute--> <h1> <span style="color: green;">Tutorials</span>point </h1> <p style="margin-top: -20px; margin-left: 100px"> Simply Easy Learning </p> </body> </html>
Override style attribute value
As you have seen in the previous example that inline CSS is the most prioritize CSS that browsers follow. But if we use !important as color: black !important;
then we can override style attribute value.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML style attribute</title> <style> span{ color: black !important; } </style> </head> <body> <!-- Example of style attribute--> <h1> <span style="color: green;">Tutorials</span>point </h1> <p style="margin-top: -20px; margin-left: 100px"> Simply Easy Learning </p> </body> </html>
Supported Browsers
Attribute | |||||
---|---|---|---|---|---|
style | Yes | Yes | Yes | Yes | Yes |
To Continue Learning Please Login
Login with Google