0% found this document useful (0 votes)
2 views

HTML Styles

The document provides an overview of the HTML style attribute, explaining how to use it to apply CSS properties such as background color, text color, font family, font size, and text alignment to HTML elements. It includes examples demonstrating each property and concludes with a summary of key points. Additionally, there is an exercise to reinforce understanding of how to apply background colors in HTML.

Uploaded by

Asif Ali
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

HTML Styles

The document provides an overview of the HTML style attribute, explaining how to use it to apply CSS properties such as background color, text color, font family, font size, and text alignment to HTML elements. It includes examples demonstrating each property and concludes with a summary of key points. Additionally, there is an exercise to reinforce understanding of how to apply background colors in HTML.

Uploaded by

Asif Ali
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

 Tutorials  Exercises  Services   Sign Up Log in

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 »

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.
 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>

<h1 style="background-color:powderblue;">This is a heading</h1>


<p style="background-color:tomato;">This is a paragraph.</p>

</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

<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>

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 »

Video: HTML Styles


 Tutorials  Exercises  Services   Sign Up Log in

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++

❮ Previous Next ❯

Track your progress - it's free! Sign Up Log in

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

GET CERTIFIED FOR TEACHERS

FOR BUSINESS CONTACT US

Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial

 Tutorials  Java Tutorial


Exercises 
C++ Tutorial
Services   Sign Up Log in
jQuery Tutorial
HTML
 CSS JAVASCRIPT SQL
Top References PYTHON JAVA PHP HOW TO W3.CSS C C++

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.

You might also like