HTML Background


By default, webpage background is white in color. You may not like it, but no worries. HTML provides you following two good ways to decorate your webpage background.

  • Html Background with Colors
  • Html Background with Images

Html Background with Colors

The bgcolor attribute is used to control the background of an HTML element, specifically page body and table backgrounds.

Syntax

<tagname bgcolor="Color Value" .. >

This Color Value can be given in any different formats:

Example

 <table border="2"  bgcolor="Indigo"> 
               <tr>
               <td>Row 1 , Column 1</td>
               <td>Row 2 , Column 1</td>
               </tr>
          </table>
          
          <table border="2"  bgcolor="#D97BFD"> 
               <tr>
               <td>Row 1 , Column 1</td>
               <td>Row 2 , Column 1</td>
               </tr>
          </table>
          
          <table border="2"  bgcolor="rgb(201,12,34)"> 
               <tr>
               <td>Row 1 , Column 1</td>
               <td>Row 2 , Column 1</td>
               </tr>
          </table>
Output
Row 1 , Column 1 Row 2 , Column 1
Row 1 , Column 1 Row 2 , Column 1
Row 1 , Column 1 Row 2 , Column 1

Html Background with Images

The background attribute can also be used to control the background of an HTML elmement, specifically page body and table backgrounds. You can specify an image to set background of your HTML page or table. Following is the syntax to use background attribute with any HTML tag.

Syntax

<tagname background="Image url" .. >

The most frequently used image formats are JPEG, GIF and PNG images.

Example

<table border="2"  background="image/html/cm.png"> 
               <tr>
               <td>Row 1 , Column 1</td>
               <td>Row 2 , Column 1</td>
               </tr>
          </table>
Output
Row 1 , Column 1 Row 2 , Column 1

Share this article on