Set Background Color using CSS (original) (raw)

Last Updated : 24 Jun, 2024

Setting the background color in CSS involves using the background-color property to define the color displayed behind the content within an HTML element. This can be achieved through three primary methods: inline CSS, internal CSS, and external CSS. Each method offers different advantages depending on the use case.

**The background color can be changed in three ways:

Table of Content

1. Setting the background color using Inline CSS

Inline CSS involves adding the style attribute directly within the HTML element's opening tag. This method is straightforward for quick, specific changes but can make your HTML code harder to manage if overused.

**Setting the background color using Inline CSS Syntax

**Setting the background color using Inline CSS Example

Below is an example that illustrates the use of inline CSS.

HTML `

GeeksForGeeks

<h3 style="text-align:center;">
    How to change color of Background?
</h3>

`

**Output:

Setting the background color using Inline CSS

Explanation:

2. Setting the background color using Internal CSS

Internal CSS involves defining a

**Setting the background color using Internal CSS Example:

Below is the example that illustrates the use of internal CSS.

HTML `