View video tutorial

CSS Background

CSS

The CSS background attribute is used to add background effects to elements.

CSS background

➔ Background colors and background images are used in the following sections..

➔ The CSS background property is used to set the background effect on the element.

➔ The following are CSS background properties that affect HTML elements.

  • background-color
  • background-image
  • background-repeat
  • background-attachment
  • background-position
  • background (shorthand property)

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <title>CSS Bangladesh Example</title>
</head>
<body>
  <div style=" background:#BEC2C4;border-radius: 5px; padding:10px;">
    <p>The CSS background property is used to set the background effect on the element.</p>
    <p>The following are CSS background properties that affect HTML elements.</p>
  </div>
</body>
</html>
Try it Now »

Example

<!DOCTYPE html>
<html lang="en">
<head>
    <title>CSS background Example</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta charset="utf-8" />
    <style>
       div{
         background:#abcdef url("resources/images/flowers-tulip-t.png");
         border-radius: 5px; 
         padding:10px;
         min-height:230px;
       }
    </style>
</head>
<body>
    <div>
        <p>The CSS background property is used to set the background effect on the element.</p>
        <p>The following are CSS background properties that affect HTML elements.</p>
    </div>
</body>
</html>
Try it Now »

Copy the code and click on the "Try it Now" button to see how it works.