HTML Style Attribute

Style attribute is used for setting the style of an HTML element by setting CSS properties.

The HTML style attribute has the following syntax:

<tagname style=”property1:value1;property2:value2;”>

Background Color

The CSS background-color property defines the background color for an HTML element.

Background Color Example

<body style=”background-color:grey;”>

<h1>This is a heading</h1>
<p>This is a paragraph.</p>

</body>

Text Color

The CSS color property defines the text color for an HTML element.

Text Color Example

<p style=”color:blue;”>My Paragraph.</p>

Fonts

The CSS font-family property defines the font to be used for an HTML element.

Fonts Example

<p style=”font-family:verdana;”>My Paragraph.</p>

Text Size

The CSS font-size property defines the text size for an HTML element.

Text Size Example

<p style=”font-size:18px;”>My Paragraph.</p>

Text Alignment

The CSS text-align property defines the horizontal text alignment for an HTML element.

Text Alignment Example

<p style=”text-align:center;”>My Paragraph.</p>