CSS – Set Background Color for Paragraph

To set a specific background color for Paragraph element using CSS, set background-color property with required color value in style(inline/external).

Example

In the following HTML script, we have set background colors yellow, rgb(255, 163, 132), and hsl(190, 46%, 63%) for paragraphs with ids p1, p2, and p3 respectively.

index.html

</>
Copy
<!DOCTYPE html>
<html lang="en">
    <head>
        <style>
            #p1 {
                background-color: yellow;
            }
            #p2 {
                background-color: rgb(255, 163, 132);
            }
            #p3 {
                background-color: hsl(190, 46%, 63%);
            }
        </style>
    </head>
    <body>
        <p>A paragraph with default background color.</p>
        <p id="p1">A paragraph with background color.</p>
        <p id="p2">A paragraph with background color using RGB.</p>
        <p id="p3">A paragraph with background color using HSL.</p>
    </body>
</html>

Conclusion

In this CSS Tutorial, we learned how to set background color for paragraph element(s) using CSS.