The HTML style attribute is used to add styles to an element, such as color, font, size, and more.
The HTML style attribute has the following syntax:
<tagname
style="property:value;">
The property is a CSS property. The value is a CSS value.
Background Color
The CSS background-color
property defines the background color
for an HTML element.
Example
<!DOCTYPE>
<html>
<title>HTML Tutorials</title>
<body style="background-color:powderblue;">
<h1>This is a Heading </h1>
<p>This is a paragraph.</p>
</body>
</html>
Output
Set background color for two different elements:
Example
<!DOCTYPE>
<html>
<title>HTML Tutorials</title>
<body>
<h1 style="background-color:blue;">This is a heading</h1>
<p style="background-color:red;">This is a paragraph.</p>
</body>
</html>
Output
The CSS color property defines the text color for an HTML element:
Example
<!DOCTYPE>
<html>
<title>HTML Tutorials</title>
<body>
<h1 style="color:blue;">This is a heading</h1>
<p style="color:red;">This is a paragraph.</p>
</body>
</html>
Output
The CSS font-family property defines the font to be used for an HTML element:
Example
<!DOCTYPE>
<html>
<title>HTML Tutorials</title>
<body>
<h1 style="font-family:verdana;">Twinkle, twinkle, little star</h1>
<p style="font-family:courier;">Twinkle, twinkle, little star</p>
</body>
</html>
Output
The CSS font-size property defines the text size for an HTML element:
Example
<!DOCTYPE>
<html>
<title>HTML Tutorials</title>
<body>
<p style="font-size:300%;">Twinkle, twinkle, little star</p>
<p style="font-size:150%;">Twinkle, twinkle, little star</p>
</body>
</html>
Output
The CSS text-align
property defines the horizontal text alignment for an HTML element:
Example
<!DOCTYPE>
<html>
<title>HTML Tutorials</title>
<body>
<p style="text-align:left;">Twinkle, twinkle, little star</p>
<p style="text-align:center;">Twinkle, twinkle, little star</p>
<p style="text-align:right;">Twinkle, twinkle, little star</p>
</body>
</html>
No comments:
Post a Comment