<htmlstart/>

HTML Styles

The style attribute adds CSS directly to any HTML element.

The style Attribute

Use the style attribute to add CSS directly to an element. The value is a CSS property-value pair.

<p style="color: red;">This text is red.</p>
<h1 style="font-size: 32px; color: #D62828;">Big red heading</h1>

Common Style Properties

PropertyWhat it doesExample value
colorText colorred, #333
background-colorBackground color#f5f5f5
font-sizeText size18px, 1.2rem
font-familyTypefaceArial, sans-serif
text-alignText alignmentcenter, left
borderBorder shorthand1px solid #ccc
paddingInner spacing16px
<h2 style="font-family: Arial; text-align: center; color: #5B3FEF;">
  Centered purple heading
</h2>

<p style="background-color: #fff3cd; padding: 12px; border-left: 4px solid #f0c33a;">
  Highlighted note paragraph.
</p>
Inline styles are great for quick tests. For real projects always use an external CSS file — inline styles are hard to maintain and can't be reused.