Used to add background to an element.
A range of properties to control the backgrounds of HTML elements, allowing you to set colors, images, gradients, and more. Let's see some of the properties used in css
This property sets the background color of an element.
You can use different color representations, such as named colors, hexadecimal values, RGB values, or HSL values.
Example
<!DOCTYPE html>
<html>
<head>
<title>Background Example 1</title>
<style>
p {
background-color: #F0F8FF;
}
</style>
</head>
<body>
<p>Background Changed</p>
</body>
</html>
This property defines how the background image should be repeated if it's smaller than the element.
Values include repeat (default), repeat-x (horizontal), repeat-y (vertical), and no-repeat.
Example
<!DOCTYPE html>
<html>
<head>
<title>Background Example 3</title>
<style>
p {
background-image: url('background.jpg'); /* add an image */
background-repeat: no-repeat;
}
</style>
</head>
<body>
<p>Background Changed</p>
</body>
</html>
This property determines the size of the background image.
You can use lengths, percentages, or special keywords like cover (scales the image to cover the entire element) and contain (scales the image to fit within the element).
Example
<!DOCTYPE html>
<html>
<head>
<title>Background Example 4</title>
<style>
p {
background-image: url('background.jpg'); /* add an image */
background-size: cover;
}
</style>
</head>
<body>
<p>Background Changed</p>
</body>
</html>
This property sets the starting position of the background image.
You can use keywords like top, bottom, left, right, and combinations like center center.
Example
<!DOCTYPE html>
<html>
<head>
<title>Background Example 5</title>
<style>
p {
background-image: url('background.jpg'); /* add an image */
background-position: center top;
}
</style>
</head>
<body>
<p>Background Changed</p>
</body>
</html>
The Concepts and codes you leart practice in Compilers till you are confident of doing on your own. A Various methods of examples, concepts, codes availble in our websites. Don't know where to start Down some code examples are given for this page topic use the code and compile or Try on own Now