0% found this document useful (0 votes)
52 views10 pages

HTML Styles

The document discusses using the HTML style attribute to style elements by setting CSS properties like background color, text color, font, size, and alignment directly in the element. It provides examples of styling body, headings, and paragraphs with different background colors, text colors, fonts sizes, and text alignment.

Uploaded by

Sanando Banerjee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views10 pages

HTML Styles

The document discusses using the HTML style attribute to style elements by setting CSS properties like background color, text color, font, size, and alignment directly in the element. It provides examples of styling body, headings, and paragraphs with different background colors, text colors, fonts sizes, and text alignment.

Uploaded by

Sanando Banerjee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

3/17/23, 5:41 PM HTML Styles

 Bootcamp Menu  Sign Up Log in


Dark mode

Dark code
  HTML CSS   

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:

https://www.w3schools.com/html/html_styles.asp 1/10
3/17/23, 5:41 PM HTML Styles

<tagname
style="property:value;">

The property is a CSS property. The value is a CSS value.

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>

https://www.w3schools.com/html/html_styles.asp 2/10
3/17/23, 5:41 PM HTML Styles

Try it Yourself »

ADVERTISEMENT

Text Color
The CSS color property defines the text color for an HTML element:

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

https://www.w3schools.com/html/html_styles.asp 3/10
3/17/23, 5:41 PM HTML Styles

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

https://www.w3schools.com/html/html_styles.asp 4/10
3/17/23, 5:41 PM HTML Styles

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

HTML Exercises

Test Yourself With Exercises

Exercise:
Use the correct HTML attribute, and CSS, to set the color of the paragraph to
"blue".

<p =" ;">This is a paragraph.</p>

Submit Answer »

Start the Exercise

❮ Previous Next ❯

ADVERTISEMENT

https://www.w3schools.com/html/html_styles.asp 5/10
3/17/23, 5:41 PM HTML Styles

COLOR PICKER

https://www.w3schools.com/html/html_styles.asp 6/10
3/17/23, 5:41 PM HTML Styles




Get certified

by completing

a HTML

course today!

school
w3 s

3
CE

02

TI 2
R

FI .
ED

Get started

ADVERTISEMENT

https://www.w3schools.com/html/html_styles.asp 7/10
3/17/23, 5:41 PM HTML Styles

ADVERTISEMENT

ADVERTISEMENT

https://www.w3schools.com/html/html_styles.asp 8/10
3/17/23, 5:41 PM HTML Styles

Report Error

Spaces

Upgrade

Newsletter

Get Certified

Top Tutorials
HTML Tutorial

CSS Tutorial

JavaScript Tutorial

How To Tutorial

SQL Tutorial

Python Tutorial

W3.CSS Tutorial

Bootstrap Tutorial

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

https://www.w3schools.com/html/html_styles.asp 9/10
3/17/23, 5:41 PM HTML Styles

Angular Reference

jQuery Reference

Top Examples
HTML Examples

CSS Examples

JavaScript Examples

How To Examples

SQL Examples

Python Examples

W3.CSS Examples

Bootstrap Examples

PHP Examples

Java Examples

XML Examples

jQuery Examples

Get Certified
HTML Certificate

CSS Certificate

JavaScript Certificate

Front End Certificate

SQL Certificate

Python Certificate

PHP Certificate

jQuery Certificate

Java Certificate

C++ Certificate

C# Certificate

XML Certificate

FORUM |
ABOUT

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-2023 by Refsnes Data. All Rights Reserved.

W3Schools is Powered by W3.CSS.

https://www.w3schools.com/html/html_styles.asp 10/10

You might also like