style attribute
HTML elements can be styled in three ways. Namely:
- Inline style
- Internal style
- External style
style
HTML attributes are used for inline styling . style
All CSS properties can be used in attributes.
Syntax
content
Set the color of text using the style attribute
color
The text of an HTML element is colored through properties.
Examples
HTML style attributes
The color of this paragraph has been changed to teal using the style attribute.
Output
The color of this paragraph has been changed to teal using the style attribute.
Set background color using style attribute
background-color
The background color of an HTML element is set through a property.
Examples
HTML style attribute
Table of Contents
Toggle
This is Heading
This is a paragraph.
Output
This is Heading
This is a paragraph.
Setting the font using the style attribute
font-family
The font of an HTML element is set through properties.
Examples
HTML style attribute
This is a paragraph.
This is a paragraph.
Output
This is a paragraph.
This is a paragraph.
Set text size using style attribute
font-size
The text size of an HTML element is determined through properties.
Examples
HTML style attributes
This is a paragraph.
This is a paragraph.
Output
This is a paragraph.
This is a paragraph.
Set text alignment using the style attribute
text-align
The position of the content of an HTML element is determined through properties.
Examples
HTML style attributes
This paragraph will be centered.
This paragraph will be right.
Output
This paragraph will be centered.
This paragraph will be right.
Chapter summary
style
Attributes are used to style HTML elements inline .color
Properties are used to set the color of the text .background-color
The property is used to set the background color .font-family
Properties are used to set the font of text .font-size
Properties are used to determine the size of the text .text-align
Used to determine the location of content .