You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The **`HTMLTableCellElement.bgColor`** property is used to set the background color of a cell or get the value of the obsolete [`bgColor`](/en-US/docs/Web/HTML/Element/td#bgcolor) attribute, if present.
12
+
13
+
**Note:** This property is deprecated and CSS should be used to set the background color. Use the {{cssxref("background-color")}} property instead.
14
+
15
+
## Value
16
+
17
+
One of the following value types can be used:
18
+
19
+
- a named color, like `red` or `blue`
20
+
- a hex code, like `#0000dd` or `#00d`
21
+
22
+
** Note: ** The values accepted here are a limited subset of the CSS color values. Only {{cssxref("named-color")}} and 3- or 6-digit {{cssxref("hex-color")}} (with no alpha-channel). While all HTML color values are valid in CSS, this is not true in the other direction.
23
+
24
+
## Examples
25
+
26
+
Use CSS `background-color` instead. An example of using [`background-color` with HTML table elements](/en-US/docs/Web/CSS/background-color#colorize_tables) is available on the {{cssxref("background-color")}} page.
The **`HTMLTableRowElement.bgColor`** property is used to set the background color of a row or retrieve the value of the obsolete [`bgColor`](/en-US/docs/Web/HTML/Element/tr#bgcolor) attribute, if present.
12
+
13
+
**Note:** This property is deprecated and CSS should be used to set the background color. Use the {{cssxref("background-color")}} property instead.
14
+
15
+
## Value
16
+
17
+
One of the following value types can be used:
18
+
19
+
- a named color, like `red` or `blue`
20
+
- a hex code, like `#0000dd`
21
+
22
+
**Note:** The values accepted here are a subset of the CSS color values. You can reuse HTML color values in CSS, but not in the other direction: the unknown colors would appear differently than expected.
23
+
24
+
## Examples
25
+
26
+
Use CSS `background-color` instead. An [example](/en-US/docs/Web/CSS/background-color#colorize_tables) is available on the {{cssxref("background-color")}} page.
Copy file name to clipboardExpand all lines: files/en-us/web/css/background-color/index.md
+64-4Lines changed: 64 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -73,7 +73,11 @@ Color contrast ratio is determined by comparing the luminance of the text and ba
73
73
74
74
## Examples
75
75
76
-
### HTML
76
+
### Colorize boxes
77
+
78
+
This example demonstrates the applying `background-color` to HTML {{HTMLelement("div")}} elements using different CSS {{cssxref("color_value", "<color>")}} values.
79
+
80
+
#### HTML
77
81
78
82
```html
79
83
<div class="exampleone">Lorem ipsum dolor sit amet, consectetuer</div>
@@ -83,7 +87,7 @@ Color contrast ratio is determined by comparing the luminance of the text and ba
83
87
<div class="examplethree">Lorem ipsum dolor sit amet, consectetuer</div>
84
88
```
85
89
86
-
### CSS
90
+
#### CSS
87
91
88
92
```css
89
93
.exampleone {
@@ -101,9 +105,65 @@ Color contrast ratio is determined by comparing the luminance of the text and ba
101
105
}
102
106
```
103
107
104
-
### Result
108
+
#### Result
109
+
110
+
{{EmbedLiveSample("Colorize boxes", 200, 150)}}
111
+
112
+
### Colorize tables
113
+
114
+
This example demonstrates the use of `background-color` on HTML {{HTMLelement("table")}} elements, including {{HTMLelement("tr")}} rows and {{HTMLelement("td")}} cells.
0 commit comments