Advertisement

Responsive Advertisement

HTML COLOR

In HTML, colors are used to style details (text, borders, backgrounds, buttons, etc.) and control the layout appearance through CSS. The modern way is to use CSS with your HTML.

1. Adding colors to HTML elements

Inline CSS:

<p style="color: blue;">This text is blue.
</p>
<div style="background-color: yellow;">
 This box has a yellow background.
</div>
2. Using color names
<h1 style="color: red;">Red Heading</h1>
<p style="color: green;">Green paragraph</p>

Common color names:

  • red
  • blue
  • green
  • black
  • white
  • yellow
  • orange
  • purple

3. Using HEX colors

HEX colors start with #:

<h2 style="color: #ff0000;">Red using HEX</h2>
<div style="background-color: #3498db;">
Blue background
</div>

Examples:

  • #000000 = black
  • #ffffff = white
  • #ff0000 = red
  • #00ff00 = green
  • #0000ff = blue

4. Using RGB colors

<p style="color: rgb(255, 0, 0);">
  Red text
</p>
<div style="background-color: rgb(0, 150, 255);">
Blue box
</div>

5. Styling layout with colors and CSS

Example page:

<!DOCTYPE html>

<html>

<head>

<style>

body {

  background-color: #f2f2f2;

  font-family: Arial;

}

.header {

  background-color: #333;

  color: white;

  padding: 20px;

  text-align: center;

}

.content {

  background-color: white;

  color: #444;

  padding: 20px;

  margin: 20px;

  border: 2px solid #3498db;

}

.button {

  background-color: green;

  color: white;

  padding: 10px;

  border-radius: 5px;

}

</style>

</head>

<body>

<div class="header">

My Website

</div>

<div class="content">

<h2>Details Section</h2>

<p>This is a colored layout example.</p><button class="button">Click Me</button></div>

</body>

</html>


6. CSS properties commonly used for layout

PropertyPurpose
background-colorSets background color
colorSets text color
border-colorSets border color
paddingSpace inside an element
marginSpace outside an element
widthElement width
heightElement height
displayControls layout type
flexCreates flexible layouts

For more advanced layouts, learn CSS Flexbox and CSS Grid. They are the main tools for arranging HTML elements on a page.

Post a Comment

0 Comments