13/07/2025, 18:27 HTML Styles
Tutorials Exercises Services Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
HTML Styles
❮ Previous Next ❯
The HTML style attribute is used to add styles to an element, such as color,
font, size, and more.
Example
I am Red
I am Blue
I am Big
Try it Yourself »
The HTML Style Attribute
Setting the style of an HTML element, can be done with the style attribute.
The HTML style attribute has the following syntax:
<tagname style="property:value;">
The property is a CSS property. The value is a CSS value.
https://www.w3schools.com/html/html_styles.asp 1/7
13/07/2025, 18:27 HTML Styles
Tutorials Exercises Services
You will learn more about CSS later in this tutorial.
Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
Background Color
The CSS background-color property defines the background color for an HTML
element.
Example
Set the background color for a page to powderblue:
<body style="background-color:powderblue;">
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
Try it Yourself »
Example
Set background color for two different elements:
<body>
<h1 style="background-color:powderblue;">This is a heading</h1>
<p style="background-color:tomato;">This is a paragraph.</p>
</body>
Try it Yourself »
https://www.w3schools.com/html/html_styles.asp 2/7
13/07/2025, 18:27 HTML Styles
Text Tutorials
Color Exercises Services Sign In
HTML CSScolorJAVASCRIPT
The CSS SQLthe text
property defines PYTHON
color forJAVA PHP
an HTML HOW TO
element: W3.CSS C
Example
<h1 style="color:blue;">This is a heading</h1>
<p style="color:red;">This is a paragraph.</p>
Try it Yourself »
Fonts
The CSS font-family property defines the font to be used for an HTML element:
Example
<h1 style="font-family:verdana;">This is a heading</h1>
<p style="font-family:courier;">This is a paragraph.</p>
Try it Yourself »
Text Size
The CSS font-size property defines the text size for an HTML element:
Example
<h1 style="font-size:300%;">This is a heading</h1>
<p style="font-size:160%;">This is a paragraph.</p>
https://www.w3schools.com/html/html_styles.asp 3/7
13/07/2025, 18:27 HTML Styles
Try it Yourself »
Tutorials Exercises Services Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
Text Alignment
The CSS text-align property defines the horizontal text alignment for an HTML
element:
Example
<h1 style="text-align:center;">Centered Heading</h1>
<p style="text-align:center;">Centered paragraph.</p>
Try it Yourself »
Chapter Summary
Use the style attribute for styling HTML elements
Use background-color for background color
Use color for text colors
Use font-family for text fonts
Use font-size for text sizes
Use text-align for text alignment
?
Exercise
What is a correct way to add a background color to an HTML document?
<body style='background-color:pink;'>
<body background-color='pink;'>
<body style='bgcolor:pink;'>
https://www.w3schools.com/html/html_styles.asp 4/7
13/07/2025, 18:27 HTML Styles
Tutorials Exercises Services
Submit Answer »
Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
Video: HTML Styles
❮ Previous Next ❯
Track your progress - it's free! Sign Up Log in
https://www.w3schools.com/html/html_styles.asp 5/7
13/07/2025, 18:27 HTML Styles
Tutorials Exercises Services Sign In
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C
COLOR PICKER
PLUS SPACES
GET CERTIFIED FOR TEACHERS
FOR BUSINESS CONTACT US
Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
https://www.w3schools.com/html/html_styles.asp 6/7
13/07/2025, 18:27 HTML Styles
How To Tutorial
Tutorials SQL Tutorial
Exercises
Python Tutorial
Services Sign In
W3.CSS Tutorial
HTML
CSS JAVASCRIPTTutorialSQL
Bootstrap PYTHON JAVA PHP HOW TO W3.CSS C
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial
Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
Angular Reference
jQuery Reference
Top Examples Get Certified
HTML Examples HTML Certificate
CSS Examples CSS Certificate
JavaScript Examples JavaScript Certificate
How To Examples Front End Certificate
SQL Examples SQL Certificate
Python Examples Python Certificate
W3.CSS Examples PHP Certificate
Bootstrap Examples jQuery Certificate
PHP Examples Java Certificate
Java Examples C++ Certificate
XML Examples C# Certificate
jQuery Examples XML Certificate
FORUM ABOUT ACADEMY
W3Schools is optimized for learning and training. Examples might be simplified to improve
reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot
warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted our terms of
use, cookie and privacy policy.
Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by
W3.CSS.
https://www.w3schools.com/html/html_styles.asp 7/7