HTML Styles
"HTML Styles" isn't a single, specific element or code within HTML : These are styles defined directly within an HTML element using the style attribute. Add styles to an element, such as color, font, size, and more.
The HTML Style Attribute
Setting the style of an HTML element, can be done with the style attribute.
The HTML style attribute has the following Example:
Example
<p style="color: blue; font-size: 16px;">This is a styled paragraph.</p>You can click on above box to edit the code and run again.
Output
This is a styled paragraph.
Background Colors
The CSS background-color
property defines the background color for an HTML element.
Example
<html> <body style="background-color: lightblue;"> <h1>This is a page with a light blue background.</h1> <p>This is some content on the page.</p> </body> </html>You can click on above box to edit the code and run again.
Output
This is a page with a light blue background.
This is some content on the page.
Text Color
The CSS color property
defines the text color for an HTML element:
Example
<html> <body> <h1 style="color: blue;">This is a heading with blue text color.</h1> <p style="color: green;">This is a paragraph with green text color.</p> </body> </html>You can click on above box to edit the code and run again.
Output
This is a heading with blue text color.
This is a paragraph with green text color.
Fonts
IThe CSS font-family
property defines the font to be used for an HTML element:
Example
<body> <p style="font-family: 'Arial', sans-serif;">This is a paragraph with the Arial font.</p> <p style="font-family: 'Times New Roman', serif;">This is another paragraph with the Times New Roman font.</p> </body>You can click on above box to edit the code and run again.
Output
This is a paragraph with the Arial font.
This is another paragraph with the Times New Roman font.
Text Size
The CSS font-size
property defines the text size for an HTML element:
Example
<body> <p style="font-size: 18px;">This is a paragraph with a font size of 18 pixels.</p> <p style="font-size: 22px;">This is another paragraph with a font size of 22 pixels.</p> </body>You can click on above box to edit the code and run again.
Output
This is a paragraph with a font size of 18 pixels.
This is another paragraph with a font size of 22 pixels.
Text Alignment
The CSS text-align
property defines the horizontal text alignment for an HTML element:
Example
<body> <p style="text-align: left;">left-aligned text.</p> <p style="text-align: center;">center-aligned text.</p> <p style="text-align: right;">right-aligned text.</p> <p style="text-align: justyfy;">justified text.</p> </body>You can click on above box to edit the code and run again.
Output
left-aligned text.
center-aligned text.
right-aligned text.
justified text.