Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML attribute bgcolor is deprecated: What To Use Instead?

Tags:

html

asp.net

VStudio ASP.NET gives the following message:

Attribute 'bgcolor' is considered outdated. A newer construct is recommended.

What is the recommended construct?

bgcolor is within a <td> element.
Another related message is :

Attribute 'bordercolor' is not a valid attribute of element 'table'.  

Does anyone know where I might find the newer replacements?

like image 336
Anthony K Avatar asked Dec 12 '08 01:12

Anthony K


People also ask

What can I use instead of bgcolor?

The newer replacement is cascading style sheets (CSS).

Which version of HTML does not support the bgcolor attribute?

The HTML5 does not support the bgcolor attribute.

Which attribute overrides the bgcolor attribute?

The bgcolor attribute deprecated in HTML5. Just keep in mind, the usage of style attribute overrides any style set globally. It will override any style set in the HTML <style> tag or external style sheet.

Is bgcolor supported in HTML5?

Note: The bgcolor attribute is not supported in HTML5.


2 Answers

BGColor was deprecated in the W3C HTML 4.0 Specification.

Newer Web sites and web applications use CSS (Cascading Style Sheets) to render the same thing, as follows:

   body {
  background-color : #ffffff;
}

For tables, do the following:

<table>

<tr id="row1">
   <th>Header 1</th>      <td>Cell 1</td>        <td>Cell 2</td>
</tr>
<tr id="row2">
   <th>Header 2</th>      <td>Cell 3</td>        <td>Cell 4</td>
</tr>
<tr id="row3">
   <th>Header 3</th>      <td>Cell 5</td>        <td>Cell 6</td>
</tr>
</table>

And in your CSS:

th { text-align: center; font-weight: bold; vertical-align: baseline }

td { vertical-align: middle  }

table  { border-collapse: collapse; background-color: #ffffff }
tr#row1 { border-top: 3px solid blue }
tr#row2 { border-top: 1px solid black }
tr#row3 { border-top: 1px solid black }

That will make it so the table will have a background color, and do different stuff with the rest of the table data/table rows.

Simply put that in your style sheet and reference it on your web page like so:

<link rel="stylesheet" href="style.css" TYPE="text/css" media="screen">

You can put just about whatever you like in your CSS, more information on CSS here, and here.

like image 58
George Stocker Avatar answered Oct 12 '22 08:10

George Stocker


Best guess would be CSS's background-color and border-color:

<table style="border-color: #ffffff;">

<td style="background-color: #000000;">
like image 22
Jonathan Lonowski Avatar answered Oct 12 '22 07:10

Jonathan Lonowski