HTML Style Attribute
style attribute in HTML allows you to apply inline styles to individual elements. This means you can specify styling directly within the HTML tag rather than in a separate CSS file. The syntax for the
style attribute is as follows:
Here’s a breakdown of the key components:
tagname: Replace this with the HTML tag you want to style (e.g.,
h1for headers, etc.).
style: This is the attribute name. It tells the browser that you are going to provide styling information.
property: Replace this with the specific CSS property you want to apply (e.g.,
value: Replace this with the desired value for the CSS property.
HTML Style Attribute Example
This is a styled paragraph.
Centered Heading with Green Color
In this example, the
style attribute is used to apply styles directly to a paragraph (
<p>) and a heading (
<h2>). Multiple styles are separated by a semicolon.
Common Styling Properties:
Here are some common CSS properties you can use with the
- color: Text color
- font-size: Font size
- font-family: Font family
- background-color: Background color
- text-align: Text alignment
- margin, padding: Spacing around the element
- border: Border around the element
Remember that while the
style attribute is convenient for quick styling, it’s often recommended to use an external CSS file for larger projects to maintain a clear separation of structure and presentation. The
style attribute is useful for small-scale styling within individual HTML tags.