Artboard 2

Build the internet on DigitalOcean with ☁️ Servers, Managed DBs, K8s. 💰 Start free with a $100 credit.

Styles in HTML

This property specifies the color of the background for an html element.

html elements can be styled with the style attribute.

style attribute syntax

<tag style="property-name: value;"></tag>

Note: The property & value are CSS property & value.

Note: You can learn about CSS in detail in the CSS tutorial.

background-color Property

This property specifies the color of the background for an html element.

Example: Setting color of body background to green.

<body style="background-color: green">
  <h1>Hello</h1>
  <h2>World</h2>
</body>
Backgorund color Devhoot

color property

The color property sets the text color of an element.

<body style="background-color: green">
  <h1 style="color:white">Hello</h1>
  <h2 style="color:yellow">World</h2>
</body>
color Devhoot

font-family property

The font-family property specifies the font-family of an element.

<body>
  <h1 style="font-family: Arial">Hello</h1>
  <h2 style="font-family: Verdana">World</h2>
</body>
font-family Devhoot

font-size property

The font-size property specifies the size of text for an element.

<body>
  <h1 style="font-size: 12px">Hello</h1>
  <h2 style="font-size: 32px">World</h2>
</body>
font-size Devhoot

text-align property

The text-align aligns text horizontally.

<body>
  <h1 style="text-align: center">Hello</h1>
  <h2 style="text-align: right">World</h2>
</body>
text-align Devhoot