Learn how to use the bgcolor and text attributes in the <body> tag to set background and text colors in HTML.
To create an HTML webpage that demonstrates the use of bgcolor and text attributes in the <body> tag to set background color and text color.
The <body> tag has two important attributes for controlling colors:
bgcolor — Sets the background color of the entire webpage.text — Sets the default color of all text on the webpage.bgcolor and text attributes are deprecated in HTML5. Use CSS instead: style="background-color: color;" and style="color: color;". However, these attributes are still supported and useful for learning purposes.
Dark background, white text
Yellow background, dark text
Red background, white text
Green background, white text
| Value Type | Example | Description |
|---|---|---|
| Color Name | bgcolor="red" |
Standard color names (red, blue, green, etc.) |
| Hexadecimal | bgcolor="#ff0000" |
Hex color codes (#RRGGBB) |
| RGB | bgcolor="rgb(255,0,0)" |
RGB values (0-255 for each color) |
| RGBA | bgcolor="rgba(255,0,0,0.5)" |
RGB with alpha (transparency) — CSS only |
| Color Name | Hex Value | Color Preview |
|---|---|---|
| black | #000000 | |
| white | #ffffff | |
| red | #ff0000 | |
| green | #00ff00 | |
| blue | #0000ff | |
| yellow | #ffff00 | |
| orange | #ffa500 | |
| purple | #800080 | |
| teal | #008080 | |
| lightblue | #add8e6 |
| Mistake | Why It's Wrong | Correct Way |
|---|---|---|
Using bgcolor and text in HTML5 |
Deprecated attributes | Use CSS background-color and color |
| Misspelling attributes (e.g., "bgcolor" vs "bgcolor") | Attribute won't work | Use correct spelling: bgcolor and text |
| Using color names with spaces | Invalid color value | Use single word color names or hex codes |
Forgetting to close the <body> tag |
Invalid HTML | Always close </body> |
| Using poor contrast (e.g., white text on yellow) | Hard to read | Choose colors with good contrast |
bgcolor sets the background color of the entire page.text sets the default text color for all text on the page.style or <font> tag.You have successfully:
bgcolor and text attributes in the <body> tag.bgcolor and text are useful for learning, they are deprecated in HTML5. For new projects, always use CSS with background-color and color for better control, maintainability, and adherence to web standards.
ایک HTML ویب صفحہ بنانا جو bgcolor اور text صفات کو <body> ٹیگ میں بیک گراؤنڈ کلر اور ٹیکسٹ کلر سیٹ کرنے کے لیے استعمال کرنے کا طریقہ ظاہر کرتا ہے۔
<body> ٹیگ میں رنگوں کو کنٹرول کرنے کے لیے دو اہم صفات ہیں:
bgcolor — پورے ویب صفحے کا بیک گراؤنڈ کلر سیٹ کرتا ہے۔text — صفحے پر تمام ٹیکسٹ کا ڈیفالٹ کلر سیٹ کرتا ہے۔bgcolor اور text دونوں صفات HTML5 میں متروک (deprecated) ہیں۔ اس کی بجائے CSS استعمال کریں: style="background-color: color;" اور style="color: color;"۔ تاہم، یہ صفات اب بھی سپورٹ کی جاتی ہیں اور سیکھنے کے مقاصد کے لیے مفید ہیں۔
گہرا بیک گراؤنڈ، سفید ٹیکسٹ
پیلا بیک گراؤنڈ، گہرا ٹیکسٹ
سرخ بیک گراؤنڈ، سفید ٹیکسٹ
سبز بیک گراؤنڈ، سفید ٹیکسٹ
| قدر کی قسم | مثال | وضاحت |
|---|---|---|
| کلر نام | bgcolor="red" |
معیاری کلر نام (red، blue، green وغیرہ) |
| ہیکسا ڈیسیمل | bgcolor="#ff0000" |
ہیکس کلر کوڈز (#RRGGBB) |
| RGB | bgcolor="rgb(255,0,0)" |
RGB اقدار (ہر کلر کے لیے 0-255) |
| RGBA | bgcolor="rgba(255,0,0,0.5)" |
الفا کے ساتھ RGB (شفافیت) — صرف CSS |
| کلر نام | ہیکس قدر | کلر کا پیش منظر |
|---|---|---|
| black | #000000 | |
| white | #ffffff | |
| red | #ff0000 | |
| green | #00ff00 | |
| blue | #0000ff | |
| yellow | #ffff00 | |
| orange | #ffa500 | |
| purple | #800080 | |
| teal | #008080 | |
| lightblue | #add8e6 |
| غلطی | یہ کیوں غلط ہے | صحیح طریقہ |
|---|---|---|
HTML5 میں bgcolor اور text کا استعمال |
متروک صفات | CSS background-color اور color استعمال کریں |
| صفات کی غلط ہجے (مثلاً "bgcolor" بمقابلہ "bgcolor") | صفت کام نہیں کرے گی | صحیح ہجے استعمال کریں: bgcolor اور text |
| اسپیس کے ساتھ کلر نام کا استعمال | غلط کلر قدر | ایک لفظی کلر نام یا ہیکس کوڈ استعمال کریں |
<body> ٹیگ بند کرنا بھول جانا |
غلط HTML | ہمیشہ </body> بند کریں |
| خراب کنٹراسٹ کا استعمال (مثلاً پیلے پر سفید ٹیکسٹ) | پڑھنا مشکل | اچھے کنٹراسٹ والے کلرز کا انتخاب کریں |
bgcolor پورے صفحے کا بیک گراؤنڈ کلر سیٹ کرتا ہے۔text صفحے پر تمام ٹیکسٹ کے لیے ڈیفالٹ ٹیکسٹ کلر سیٹ کرتا ہے۔style یا <font> ٹیگ کا استعمال کرکے ڈیفالٹ ٹیکسٹ کلر کو اوور رائڈ کر سکتے ہیں۔آپ نے کامیابی سے:
<body> ٹیگ میں bgcolor اور text صفات کا استعمال کیا۔bgcolor اور text سیکھنے کے لیے مفید ہیں، یہ HTML5 میں متروک ہیں۔ نئے پروجیکٹس کے لیے، بہتر کنٹرول، دیکھ بھال، اور ویب معیارات کی پابندی کے لیے ہمیشہ CSS کو background-color اور color کے ساتھ استعمال کریں۔