Home > Software engineering >  Can I add background colors in html?
Can I add background colors in html?

Time:03-08

I'd like to know if I can add background colors instead of background images because they sometimes don't show :). Usually, I would just use the background-image: URL(""); like usual, but again, sometimes they wont show.

CodePudding user response:

You can change background with css especially, but here some example of code, I hope it will help you.

<!DOCTYPE html>
<html>
<head>
<style>
body {
  background-color: red;
}
</style>
</head>
<body>


<p>You can use custom background color also with css</p>

</body>
</html>

CodePudding user response:

You can add both the background-color and background-image on the same element for the color to serve as an alternative

CodePudding user response:

Actually, it is not bad at all to determine a background colour when working with background images.

div {
    background-image: url("https://via.placeholder.com/500/green");
    background-color: black;
    height:500px;
    width: 500px;
}
<div>123</div>

CodePudding user response:

You can use the background-color or just background property. There are 2 ways of doing it. Either you can use use css using the <style> tag, or you can just edit the css in the html element itself if you just want to add 1 line of css. Example - <div style="background: red;"></div>.

  •  Tags:  
  • html
  • Related