is it possible to set the div bg color with on css, just pure html. any suggestions would be helpful...

body { background-color: #6B6B6B; margin: 50px; font-family: Arial; color: white; font-size: 14px; font-weight: 100; line-height: .2; letter-spacing: 1px; }
<div>text</div>
3

3 Answers

Welcome to StackOverflow. I know You are New contributor in SO.

NOTE:

You are using two style attributes to div tag it is invalid..!!!

<div>text</div> 

Instead of use (if use different css style by separated by ; like below)

<div>text</div> 

Use bgColor="#6B6B6B" in body tag to change background color of body But cannot change Div background with only html. You can use inline css, that is

But

The HTML bgcolor attribute is used to set the background color of an HTML element. Bgcolor is one of those attributes that has become deprecated with the implementation of Cascading Style Sheets.

It Supports tags like Supported tags:

Supported tags likes:

<body>,<marquee>, <table>, <tbody>,<td>,<tfoot>,<th>,<thead>,<tr>

DEMO USING bgColor:

<body bgColor="#6B6B6B"> <div>text</div> </body>

DEMO WITHOUT USING bgColor:

<body> <div>text</div> </body>

NOTE:

You can add background color by using background and background-color property in CSS

2

Working Code

body { background-color: #6B6B6B; margin: 50px; font-family: Arial; color: white; font-size: 14px; font-weight: 100; line-height: .2; letter-spacing: 1px; }
<div>text</div>

Your syntax was broken for inline styles. You were specifying styles two times.

Add this CSS

body { background-color: #6B6B6B; margin: 50px; font-family: Arial; color: white; font-size: 14px; font-weight: 100; line-height: .2; letter-spacing: 1px; } .mydiv { background:red; padding:5px; color:white; } 

In HTML

<div>text</div> 
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy