HTML Styles
HTML Styles
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C 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 »
<tagname style="property:value;">
The property is a CSS property. The value is a CSS value.
Tutorials Exercises Services Sign Up Log in
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++
You will learn more about CSS later in this tutorial.
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>
</body>
Try it Yourself »
Text Tutorials
Color Exercises Services Sign Up Log in
HTML CSScolorJAVASCRIPT
The CSS SQLthe text
property defines PYTHON
color forJAVA PHP
an HTML HOW TO
element: W3.CSS C C++
Example
Try it Yourself »
Fonts
The CSS font-family property defines the font to be used for an HTML element:
Example
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>
Try it Yourself »
Text Tutorials
Alignment Exercises Services Sign Up Log in
HTML CSStext-align
The CSS JAVASCRIPT
propertySQL
definesPYTHON JAVAtext alignment
the horizontal PHP HOWforTO W3.CSS
an HTML C
element: C++
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;'>
Submit Answer »
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++
❮ Previous Next ❯
ADVERTISEMENT
Tutorials Exercises Services Sign Up Log in
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++
COLOR PICKER
Tutorials Exercises
Services Sign Up Log in
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++
ADVERTISEMENT
ADVERTISEMENT
PLUS SPACES
Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
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
Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.