How do I change the table background color with valid HTML 3.2 code? The browsers I use (the big four--IE, FF, Opera, Netscape) had no problem with the BGCOLOR tag, but that's for HTML 4, not HTML 3.2.

If at all possible I'd like to avoid CSS, nothing personal but it's just another layer to learn and screw up.

Dani AI

Generated

Short answer: HTML 3.2 does not provide a table-level attribute for setting a table background. That capability shows up in later HTML (HTML 4.x) and in practice browsers tolerated vendor/legacy attributes, but if you want a document that actually validates as HTML 3.2 there is no valid table-specific attribute to change only the table background. was essentially correct on the validation point; ’s CSS fix works in modern doctypes, which is why switching the DTD fixed validation for . (webdeveloper.com)

If remaining strictly on HTML 3.2, the only built‑in color control you can rely on is the BODY attributes (for page background). Example (valid for HTML 3.2):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head><title>HTML 3.2 example</title></head>
<body bgcolor="#FFFFCC">
  <table border=1>
    <tr><td>Content</td></tr>
  </table>
</body>
</html>

If it’s acceptable to move to HTML 4.01 Transitional (what you tried), you can use the now‑deprecated table bgcolor attribute and the document will validate under that DTD. Example (HTML 4.01 Transitional):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title>HTML 4.01 example</title></head>
<body>
  <table bgcolor="#CCCCFF" border="1">
    <tr><td>Content</td></tr>
  </table>
</body>
</html>

Best practice today: use CSS (separates content from presentation and is forward‑compatible). For modern doctypes use a class or stylesheet and set background-color. That is what and were pointing toward: CSS is the supported, future‑proof approach and the bgcolor attribute is deprecated. (devdoc.net)

Practical notes: browsers historically tolerated non‑standard presentational attributes, so you might see table bgcolor working even under a 3.2 DOCTYPE — but validators will flag it. If validation is important, pick the DTD that matches the markup you need (HTML 3.2 → only BODY color; HTML 4.x Transitional → table bgcolor; modern HTML5 → CSS).

Recommended Answers

All 7 Replies

You can't. http://www.w3.org/TR/REC-html32-19970114

But why do you want to, HTML 3.2 was superseded by HTML 4.0 in 1997. But CSS is supported, so if you truely want 3.2 level implementation you will have to learn some CSS.

Use simply CSS wasn't take you 2 years to learn! The following is nice and simple solution to background colour:

<table style="background-color: #123456">

zippee, the page still didn't validate using your suggestion. Thanks anyway.

I changed the DTD to HTML 4.01 Transitional, and the page validated. I guess for now I'll be using HTML 4.01 Transitional.

Puck - it's all in your mindset. When you realize that CSS was invented to FIX issues with HTML, or to SIMPLIFY/STANDARDIZE HTML (so that we didn't have a lot of custom-to-the-browser tags like "layer") - then perhaps learning CSS won't be such a hurdle for you.

I'm getting along fine without CSS at the moment. I'll probably be forced to learn it at some time, but the heart of my web programming (not web mark up) is PHP. Most (if not all) of my pages are static documents, as enjoyable printed out as they are on the monitor.

I'm kind of oldschool where I believe a web page's value is not in it's technology, but in the content it provides. A friend of mine recently expressed the same thing.

We simply disagree that CSS is unrelated to "content".

In fact, it allows the HTML to be solely content. Ask yourself what "BGCOLOR" has to do with the "content" of your site, and perhaps you'll see my point.

I do see your point.

The point I was trying to make was with or without CSS, my webpage if rendered exactly the same, will be of equal value to the reader. By not learning CSS at this time, I can work on improving what it contains rather than work on making it look exactly the same.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.