HTML Style Attribute

The style attribute is used to add inline styles to HTML elements. Inline styles are styles that are applied directly to an element, rather than in a separate CSS file. Inline styles are useful when you want to apply a style to a specific element, rather than a group of elements.

To use the style attribute, simply add it to the opening tag of an HTML element, like this…

Text Color
To set the color of text inside an HTML element, use the color property. Here’s an example:

In this example, we’re using the style attribute to set the color of the text to blue. Now, let’s look at some other styles you can apply using the style attribute.

Background Color
To set the background color of an HTML element, use the background-color property. Here’s an example:


Font Family
To set the font family of text inside an HTML element, use the font-family property. Here’s an example:

In this example, we’re setting the font family of the p element to Tahoma.

Font Size
To set the font size of text inside an HTML element, use the font-size property. Here’s an example:

In this example, we’re setting the font size of the p (paragraph) element to 22 pixels.

Text Alignment
To align the text inside an HTML element, use the text-align property. Here’s an example:

In this example, we’re centering the text inside the p element.

Multiple HTML Style Attribute Properties
You may use more than one HTML style attribute property as in the example below:


Note:
Remember, inline styles are useful when you want to apply a style to a specific element, rather than a group of elements.