background-color 속성을 사용하여 요소의 배경색을 지정할 수 있습니다. 표준 이름, rgb(), rgba(), hsl() 또는 hsla()로 값을 지정할 수 있습니다.
구문
CSS background-color 속성의 구문은 다음과 같습니다 -
Selector {
background-color: /*value*/
} 예시
다음 예는 CSS background-color 속성을 보여줍니다 -
<!DOCTYPE html>
<html>
<head>
<style>
p:first-of-type {
font-family: cursive;
background-color: pink;
}
p:last-child {
background-color: azure;
}
div {
margin: auto;
padding: 5px;
font-family: Helvetica;
width: 430px;
background-color: burlywood;
}
</style>
</head>
<body>
<p>
Java is a high-level programming language originally developed by Sun Microsystems.<p>
<div>
Java released in 1995</div>
<p>
Java runs on a variety of platforms such as Windows, Mac OS, and the various versions of UNIX.</p>
</body>
</html> 출력
이것은 다음과 같은 출력을 제공합니다.

예시
<!DOCTYPE html>
<html>
<head>
<style>
div {
background-color: springgreen;
}
h1 {
background-color: lightcoral;
text-align: center;
}
p {
background-color: lightseagreen;
font-size: 150%;
}
</style>
</head>
<body>
<div>
<h1>Demo</h1>
<p>This is demo text1. This is demo text2. This is demo text3. </p>
</div>
</body>
</html> 출력
이것은 다음과 같은 출력을 제공합니다 -
