HTML Style Attribute
HTML style attribute is one of the HTML attributes which is used to add style to HTML elements, such as color, font, size, etc.
Here are some styles added to the HTML element via HTML style attribute:
Style attribute examples
Here are some examples of elements styled by the style attribute:
This is a green text.
This is a red text.
The background color of this text is yellow.
The background color of this text is pink.
This text is written in the middle.
This text has been left-aligned.
The font for this text has been enlarged.
The font size of this text has been reduced.
This is a round shape
This is a square
All of this & more is possible through the style attribute.
format of style attribute syntax
See HTML style
attribute syntax format:
style attribute syntax format code
property
and value
are both CSS Property and CSS Value, These are explained in detail in the CSS Syntax Tutorial.
Use of style attribute
In this example we've used the CSS color
property which specifies the text color for an HTML element:
<p style="color:green;">This is a paragraph.</p>
This is a paragraph.
Text size
CSS font-size
property Specifies the text size for the HTML element:
<p style="font-size:130%;">This is a paragraph.</p>
This is a paragraph.
Text Alignment
The CSS text-align
property defines the horizontal text alignment for the HTML element:
<p style="text-align:right;">Right aligned paragraph.</p>
Right aligned paragraph.
Background Color
The CSS background-color
property defines the background color for the HTML element:
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
This is a paragraph.
<h1 style="background-color:tomato;">Tomato Colored Background Heading</h1>
<p style="background-color:yellow;">Yellow colored background paragraph.</p>
</body>
Yellow colored background paragraph.
We've mentioned a few attributes here to clarify the HTML attribute,You will learn a lot about HTML Attributes and their features in the next tutorials.