HTML Java

HTML Styles


HTML Styles

  • Styles in HTML are basically rules that describe how a document will be presented in a browser.
  • Style information can be either attached as a separate document or embedded in the HTML document.

Example

<html>
<body>
   <p>This is normal text</p>
   <p style="color:blue;">This is blue text.</p>
   <p style="color:red;">This is red text.</p>
   <p style="color:green;">This is green text.</p>
   <p style="font-size:10px;">This is small text.</p>
   <p style="font-size:50px;">This is big text.</p>
</body>
</html>
Try it »

Note: - Browsers automatically add some white space (a margin) before and after a paragraph.



HTML Style Attribute

Setting the style of an HTML element, can be done with the style attribute.

Syntax: <tagname style=”property:value;”>

Background Color

The CSS background-color property defines the background color for an HTML element.

Example

<html>
<body style="background-color:yellow;">
  <h1>This is the Heading</h1>   <p>This is the Paragraph.</p> </body>
</html>
Try it »


Text Color

The CSS color property defines the text color for an HTML element.

Example

<html>
<body>
   <h1 style="color:red;">This is a heading</h1>
   <p style="color:blue;">This is a paragraph.</p>
   <p style="color:yellow;">This is another paragraph.</p>
</body>
</html>
Try it »


Fonts

The CSS font-family property defines the font to be used for an HTML element.

Example

<html>
<body>
   <h1 style="font-family: Engravers MT;">This is a heading</h1>
   <p style="font-family: Consolas;">This is a paragraph.</p>
</body>
</html>
Try it »


Text Size

The CSS font-size property defines the text size for an HTML element.

Example

<html>
<body>
   <h1 style="font-size:300%;">This is a heading</h1>
   <p style="font-size:160%;">This is a paragraph.</p>
</body>
</html>
Try it »


Text Alignment

The CSS text-align property defines the horizontal text alignment for an HTML element.

Example

<html>
<body>
   <h1 style="text-align:center;">This is a Centered Heading</h1>
   <p style="text-align:left;">This is a Left aligned paragraph.</p>
   <p style="text-align:left;">This is a Center aligned paragraph.</p>
   <p style="text-align:right;">This is a Right aligned paragraph.</p>
</body>
</html>
Try it »