The HTML Style Attribute
The style attribute lets you add CSS styles directly to an HTML element. This changes how it looks.
1. Change Text Color
Use color to change text color:
<p style="color: red;">This text is red.</p>
This text is red.
2. Change Font Size
Use font-size to make text bigger or smaller:
<p style="font-size: 24px;">Big text</p>
Big text
3. Change Background Color
Use background-color to add a background color:
<p style="background-color: yellow;">Yellow background</p>
Yellow background
4. Add Border
Use border to add a border around text or element:
<p style="border: 2px solid blue; padding: 5px;">Text with border</p>
Text with border
5. Text Alignment
Use text-align to align text:
<p style="text-align: center;">This text is centered</p>
This text is centered
6. Padding & Margin
Use padding for inner space, margin for outer space:
<p style="padding: 10px; margin: 20px; border: 1px solid black;">Text with padding and margin</p>
Text with padding and margin
7. Font Family
Use font-family to change the font:
<p style="font-family: Arial, sans-serif;">This text uses Arial font</p>
This text uses Arial font
8. Text Decoration
Use text-decoration for underline or line-through:
<p style="text-decoration: underline;">Underlined text</p>
Underlined text
9. Combine Multiple Styles
You can write many styles in one style attribute, separated by semicolons:
<p style="color: white; background-color: blue; font-size: 20px; padding: 10px;"> Styled text with multiple properties </p>
Styled text with multiple properties
Next Lesson → HTML Text Formatting
Previous Lesson → HTML Links