style
style attribute
The style
attribute lets you apply CSS styles directly to an element. Although it's useful for quick adjustments, it's better to use external CSS files for better organization and easier maintenance.
Syntax
<element style="property: value; property: value;">
Example
This is a paragraph.
<h1 style="color:blue;text-align:center;">This is a header</h1>
<p style="color:green;">This is a paragraph.</p>
Applicable to
The style
attribute is a global attribute, meaning it can be used with any HTML element.
Elements | Attribute |
---|---|
All HTML elements | style |
See also
Conclusion
The style
attribute in HTML allows you to apply inline CSS directly to elements for quick styling. While it's useful for simple cases, it's recommended to use external stylesheets for better scalability and maintainability. This attribute can be applied to any HTML element.
srcset
The srcset attribute provides multiple image sources for the <img> element, allowing browsers to choose the most appropriate image based on display conditions.
tabindex
The tabindex attribute in HTML defines the order in which elements receive focus when users press the Tab key to navigate through the page. It controls the sequence of focusable elements.