Write CSS to change the text colour and background of a paragraph

Description: Create a paragraph with white text on a dark blue background, with some padding.

Hint:

  • Use color for the text and background-color for the background.
  • Add padding so the text does not touch the edges.

CSS for text colour and background

<!DOCTYPE html>
<html>
<head>
  <style>
    p {
      color: white;
      background-color: darkblue;
      padding: 12px;
    }
  </style>
</head>
<body>
  <p>White text on a dark blue background.</p>
</body>
</html>

Output in the browser:

Output in the browser

White text on a dark blue background.

How it works

  • The selector p applies the rule to every paragraph.
  • color changes the text colour, and background-color changes the area behind it.

Read CSS Colors.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.