DEV Community

Cover image for Change background color in CSS
Javav
Javav

Posted on

Change background color in CSS

Changing the background color of an element in CSS is simple and straightforward. The steps are:

  1. Select the Element: Decide which HTML element you want to change the background color for.

  2. Use background-color: Apply the background-color property in your CSS file or within a <style> tag in your HTML.

Example

HTML

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
  <div class="container">
    <p id="paragraph">This is a paragraph.</p>
    <button>Click Me</button>
  </div>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

CSS

/* Change background color of the body */
body {
  background-color: lightblue;
}

/* Change background color of an element with the class 'container' */
.container {
  background-color: lightgreen;
}

/* Change background color of an element with the id 'paragraph' */
#paragraph {
  background-color: lightyellow;
}

/* Change background color of all button elements */
button {
  background-color: lightcoral;
}

Enter fullscreen mode Exit fullscreen mode

Neon image

Resources for building AI applications with Neon Postgres πŸ€–

Core concepts, starter applications, framework integrations, and deployment guides. Use these resources to build applications like RAG chatbots, semantic search engines, or custom AI tools.

Explore AI Tools β†’

Top comments (0)

Image of PulumiUP 2025

Transform Your Cloud Infrastructure

Join PulumiUP 2025 on May 6 for Expert Insights & Demos.

Register Now

πŸ‘‹ Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay