• About
  • Contact
  • Cookie
  • Disclaimer
  • Privacy Policy
  • Change the purpose of use

Tnhelearning.edu.vn - Various useful general information portal

  • Photo
  • Bio
  • How To
  • Tech

How to Set Background Color in HTML

December 4, 2023 by admin Category: How To

You are viewing the article How to Set Background Color in HTML  at Tnhelearning.edu.vn you can quickly access the necessary information in the table of contents of the article below.

X

This article is co-authored by a team of editors and trained researchers who confirm the accuracy and completeness of the article.

The wikiHow Content Management team carefully monitors the work of editors to ensure that every article is up to a high standard of quality.

This article has been viewed 77,680 times.

This is an article on how to change the background color of the web page by editing the HTML file.

Table of Contents

  • Steps
    • Prepare Before Editing HTML
    • Create a solid color background
    • Create gradient color background
    • Create background automatically change color
  • Advice
  • Warning

Steps

Prepare Before Editing HTML

Image titled 2609629 1 2

Image titled 2609629 1 2

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/e/e8/2609629-1-2.jpg/v4-728px-2609629-1-2.jpg”,”bigUrl”:” https://www.wikihow.com/images/thumb/e/e8/2609629-1-2.jpg/v4-728px-2609629-1-2.jpg”,”smallWidth”:460,”smallHeight”:345 ,”bigWidth”:728,”bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Specify the background color you want to use. HTML colors are specified by code on a tone basis. You can use the free HTML color picker W3Schops to find the code for the color you want to use:

  • Go to https://www.w3schops.com/cpors/cpors_picker.asp using your computer’s web browser.
  • Click the base color you want to use in the “Pick a Cpor” section.
  • Select a color tone on the right side of the page.
  • Record the code shown to the right of that tone.
Image titled 2609629 2 2

Image titled 2609629 2 2

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/b/b8/2609629-2-2.jpg/v4-728px-2609629-2-2.jpg”,”bigUrl”:” https://www.wikihow.com/images/thumb/b/b8/2609629-2-2.jpg/v4-728px-2609629-2-2.jpg”,”smallWidth”:460,”smallHeight”:345 ,”bigWidth”:728,”bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Open the HTML file in your favorite text editor. For HTML5, the HTML <bgcpor> attribute is no longer supported. The background color along with all other styling on the page needs to be handled with CSS. [1] X Research Source

  • You can use Notepad++ or Notepad on a Windows computer, or use TextEdit or BBEdit on a Mac computer.
Image titled 2609629 3 2

Image titled 2609629 3 2

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/2/26/2609629-3-2.jpg/v4-728px-2609629-3-2.jpg”,”bigUrl”:” https://www.wikihow.com/images/thumb/2/26/2609629-3-2.jpg/v4-728px-2609629-3-2.jpg”,”smallWidth”:460,”smallHeight”:345 ,”bigWidth”:728,”bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Add “html” heading to the text. All styling information for the page (including the background color) needs to be placed within the <style></style> tag:

     <! DOCTYPE html > < html > < head > < style > </ style > </ head > </ html > 
Image titled 2609629 4 2

Image titled 2609629 4 2

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/2/28/2609629-4-2.jpg/v4-728px-2609629-4-2.jpg”,”bigUrl”:” https://www.wikihow.com/images/thumb/2/28/2609629-4-2.jpg/v4-728px-2609629-4-2.jpg”,”smallWidth”:460,”smallHeight”:345 ,”bigWidth”:728,”bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Create a blank line between the “style” tags. You need a line to enter additional information below the <style> tag and above the </style> tag.
Image titled 2609629 5 2

Image titled 2609629 5 2

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/0/0f/2609629-5-2.jpg/v4-728px-2609629-5-2.jpg”,”bigUrl”:” https://www.wikihow.com/images/thumb/0/0f/2609629-5-2.jpg/v4-728px-2609629-5-2.jpg”,”smallWidth”:460,”smallHeight”:345 ,”bigWidth”:728,”bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Add the “body” section. Enter the following command in the <style></style> tag:

     body { }
  • Changes to the “body” part of the CSS will affect the entire page.
  • Skip this step if you want to create a gradient background.

Create a solid color background

Image titled 2609629 6 2

Image titled 2609629 6 2

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/e/e1/2609629-6-2.jpg/v4-728px-2609629-6-2.jpg”,”bigUrl”:” https://www.wikihow.com/images/thumb/e/e1/2609629-6-2.jpg/v4-728px-2609629-6-2.jpg”,”smallWidth”:460,”smallHeight”:345 ,”bigWidth”:728,”bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Find the “html” heading of the text. This heading is usually displayed at the beginning of the text.
Image titled 2609629 7 2

Image titled 2609629 7 2

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/5/55/2609629-7-2.jpg/v4-728px-2609629-7-2.jpg”,”bigUrl”:” https://www.wikihow.com/images/thumb/5/55/2609629-7-2.jpg/v4-728px-2609629-7-2.jpg”,”smallWidth”:460,”smallHeight”:345 ,”bigWidth”:728,”bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Add the “background-cpor” attribute to the “body” section. Type background-cpor: in the brackets of the page body. You should now have a “body” section like this:

     body { background-cpor : }
  • Here you can only type “cpor” because typing “cpour” will fail.
READ More:   How to Calculate Standard Deviation
Image titled 2609629 8 3

Image titled 2609629 8 3

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/3/3a/2609629-8-3.jpg/v4-728px-2609629-8-3.jpg”,”bigUrl”:” https://www.wikihow.com/images/thumb/3/3a/2609629-8-3.jpg/v4-728px-2609629-8-3.jpg”,”smallWidth”:460,”smallHeight”:345 ,”bigWidth”:728,”bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Add the background color you like to the “background-cpor” property. Enter the code of the selected color with a semicolon next to the “background-cpor:” element to do this. For example, to create a pink background for the page, you would do the following:

     body { background-cpor : #d24dff ; } 
Image titled 2609629 9 2

Image titled 2609629 9 2

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/1/1f/2609629-9-2.jpg/v4-728px-2609629-9-2.jpg”,”bigUrl”:” https://www.wikihow.com/images/thumb/1/1f/2609629-9-2.jpg/v4-728px-2609629-9-2.jpg”,”smallWidth”:460,”smallHeight”:345 ,”bigWidth”:728,”bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Review the “style” information. The heading of the HTML document should now look like this:

     <! DOCTYPE html > < html > < head > < style > body { background-cpor : #d24dff } </ style > </ head > </ html > 
Image titled 2609629 10 2

Image titled 2609629 10 2

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/7/7e/2609629-10-2.jpg/v4-728px-2609629-10-2.jpg”,”bigUrl”:” https://www.wikihow.com/images/thumb/7/7e/2609629-10-2.jpg/v4-728px-2609629-10-2.jpg”,”smallWidth”:460,”smallHeight”:345 ,”bigWidth”:728,”bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Use “background-cpor” to set the background color of other elements. Similar to coloring the body of the page, you can use “background-cpor” to give the background color of other elements such as headings, paragraphs, etc. For example, to give the background color of the main heading (< h1>) or paragraph (<p>), you will have code like this: [2] X Research Source

     <! DOCTYPE html > < html > < head > < style > body { background-cpor : #93B874 ; } h1 { background-cpor : #00b33c ; } p { background-cpor : #FFFFFF ); } </ style > < / head > < body > < h1 > Green heading < / h1 > < p > White paragraph < / p > < / body > < / html > 

Create gradient color background

Image titled 2609629 11 2

Image titled 2609629 11 2

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/3/3e/2609629-11-2.jpg/v4-728px-2609629-11-2.jpg”,”bigUrl”:” https://www.wikihow.com/images/thumb/3/3e/2609629-11-2.jpg/v4-728px-2609629-11-2.jpg”,”smallWidth”:460,”smallHeight”:345 ,”bigWidth”:728,”bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Find the “html” heading of the text. This heading displays near the beginning of the text.
Image titled 2609629 12 2

Image titled 2609629 12 2

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/0/0a/2609629-12-2.jpg/v4-728px-2609629-12-2.jpg”,”bigUrl”:” https://www.wikihow.com/images/thumb/0/0a/2609629-12-2.jpg/v4-728px-2609629-12-2.jpg”,”smallWidth”:460,”smallHeight”:345 ,”bigWidth”:728,”bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Learn the basic syntax of this procedure. When creating gradient colors, you need two pieces of information: the starting point/angle, and the colors used to style the gradient. You can choose from multiple colors to create a gradient that has all of them, and you can choose to create a gradient color in either direction or angle. [3] X Research Sources

     background : linear-gradient ( direction / angle , cpor1 , cpor2 , cpor3 , etc. ); 
Image titled 2609629 13 2

Image titled 2609629 13 2

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/2/27/2609629-13-2.jpg/v4-728px-2609629-13-2.jpg”,”bigUrl”:” https://www.wikihow.com/images/thumb/2/27/2609629-13-2.jpg/v4-728px-2609629-13-2.jpg”,”smallWidth”:460,”smallHeight”:345 ,”bigWidth”:728,”bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Create a vertical gradient color. If you don’t set the direction, the gradient color will convert from top to bottom. To create a gradient color, you need to put the following code in the <style></style> tag:

     html { min-height : 100 % ; } body { background : -webkit- linear-gradient ( #93B874 , #C9DCB9 ); background : -o- linear-gradient ( #93B874 , #C9DCB9 ); background : -moz- linear-gradient ( #93B874 , #C9DCB9 ); background : linear-gradient ( #93B874 , #C9DCB9 ); background-cpor : #93B874 ; }
  • Each browser has a different way of displaying gradient color functionality, so you need to add more styles of commands.
READ More:   How to Prevent Soil Erosion
Image titled 2609629 14 2

Image titled 2609629 14 2

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/7/74/2609629-14-2.jpg/v4-728px-2609629-14-2.jpg”,”bigUrl”:” https://www.wikihow.com/images/thumb/7/74/2609629-14-2.jpg/v4-728px-2609629-14-2.jpg”,”smallWidth”:460,”smallHeight”:345 ,”bigWidth”:728,”bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Create gradient color that transforms in direction. If you don’t want to make the gradient color change vertically, you can add direction to the gradient color to change how the color transitions. Place the following code in the <style></style> tag: [4] X Research Source

     html { min-height : 100 % ; } body { background : -webkit- linear-gradient ( left , #93B874 , #C9DCB9 ); background : -o- linear-gradient ( right , #93B874 , #C9DCB9 ); background : -moz- linear-gradient ( right , #93B874 , #C9DCB9 ); background : linear-gradient ( to right , #93B874 , #C9DCB9 ); background-cpor : #93B874 ; }
  • You can use the “left” (left) and “right” (right) tags to try out gradients in a different direction.
Image titled 2609629 15 2

Image titled 2609629 15 2

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/c/c2/2609629-15-2.jpg/v4-728px-2609629-15-2.jpg”,”bigUrl”:” https://www.wikihow.com/images/thumb/c/c2/2609629-15-2.jpg/v4-728px-2609629-15-2.jpg”,”smallWidth”:460,”smallHeight”:345 ,”bigWidth”:728,”bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Use another property to adjust the gradient color. You can transform the gradient color in many ways.

  • For example, you can not only add more than two colors, but you can also set a percentage for each color. This is how you create the area for each color section. Here is an example of a color gradient made according to this principle:
     background : linear-gradient ( # 93B874 10 %, # C9DCB9 70 %, # 000000 90 %);
Add transparency to colors. This is the fade operation. Use the same color to make the color fade completely. You need to use the rgba() function to specify the color. The last value defines transparency: 0 for solid color and 1 for transparency.

     background : linear-gradient ( to right , rgba ( 147 , 184 , 116 , 0 ), rgba ( 147 , 184 , 116 , 1 )); 
Image titled 2609629 16 2

Image titled 2609629 16 2

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/a/a2/2609629-16-2.jpg/v4-728px-2609629-16-2.jpg”,”bigUrl”:” https://www.wikihow.com/images/thumb/a/a2/2609629-16-2.jpg/v4-728px-2609629-16-2.jpg”,”smallWidth”:460,”smallHeight”:345 ,”bigWidth”:728,”bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
See the finished code. The code used to create the gradient background of the web page should look like this:

     <! DOCTYPE html > < html > < head > < style > html { min-height : 100 % ; } body { background : -webkit- linear-gradient ( left , #93B874 , #C9DCB9 ); background : -o- linear-gradient ( right , #93B874 , #C9DCB9 ); background : -moz- linear-gradient ( right , #93B874 , #C9DCB9 ); background : linear-gradient ( to right , #93B874 , #C9DCB9 ); background-cpor : #93B874 ; } </style> < / head > <body> </body> < / html > _ _ _ _ 

Create background automatically change color

Image titled 2609629 17 2

Image titled 2609629 17 2

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/0/07/2609629-17-2.jpg/v4-728px-2609629-17-2.jpg”,”bigUrl”:” https://www.wikihow.com/images/thumb/0/07/2609629-17-2.jpg/v4-728px-2609629-17-2.jpg”,”smallWidth”:460,”smallHeight”:345 ,”bigWidth”:728,”bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Find the “html” heading of the text. This heading usually appears near the top of the text.
Image titled 2609629 18 2

Image titled 2609629 18 2

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/1/1d/2609629-18-2.jpg/v4-728px-2609629-18-2.jpg”,”bigUrl”:” https://www.wikihow.com/images/thumb/1/1d/2609629-18-2.jpg/v4-728px-2609629-18-2.jpg”,”smallWidth”:460,”smallHeight”:345 ,”bigWidth”:728,”bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Add a transition attribute to the “body” section. Enter the following code in the line below the “body {” bracket and above the closing bracket: [5] X Research source

     -webkit-animation : cporchange 60s infinite ; animation : cporchange 60s infinite ;
  • The first line of the code is for open source browsers, and the last line of the code is for other browsers.
Image titled 2609629 19 2

Image titled 2609629 19 2

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/0/0f/2609629-19-2.jpg/v4-728px-2609629-19-2.jpg”,”bigUrl”:” https://www.wikihow.com/images/thumb/0/0f/2609629-19-2.jpg/v4-728px-2609629-19-2.jpg”,”smallWidth”:460,”smallHeight”:345 ,”bigWidth”:728,”bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
Add color to the transition. You’ll now use the @keyframes rule to set the background color for the transition loop, along with how long each color should show on the page. Again, you need to enter a separate code for each type of browser. Enter the following lines of code below the closing bracket of the body of the page: [6] X Research Source

     @ -webkit-keyframes cporchange { 0 % { background : #33FFF3 ;} 25 % { background : #78281F ;} 50 % { background : #117A65 ;} 75 % { background : #DC7633 ;} 100 % { background : #9B59B6 ;} } @ keyframes cporchange { 0 % { background : #33FFF3 ;} 25 % { background : #78281F ;} 50 % { background : #117A65 ;} 75 % { background : #DC7633 ;} 100 % { background : #9B59B6 ;} }
  • Note, the two rules ( @-webkit-keyframes and @keyframes have the same background color and percentage. You need to match these two to create the same experience across all browsers.
  • The percentages ( 0% , 25% , etc.) are calculated according to the total motion time ( 60s ). When you load the page, the solid background color ( #33FFF3 ) is set at 0% . After 25% of the 60 seconds are up, the background will change to #7821F and so on.
  • You can adjust the time and color to produce the desired result.
READ More:   How to Lighten Hair Color Naturally
  • Image titled 2609629 20 2

    Image titled 2609629 20 2

    {“smallUrl”:”https://www.wikihow.com/images_en/thumb/6/6e/2609629-20-2.jpg/v4-728px-2609629-20-2.jpg”,”bigUrl”:” https://www.wikihow.com/images/thumb/6/6e/2609629-20-2.jpg/v4-728px-2609629-20-2.jpg”,”smallWidth”:460,”smallHeight”:345 ,”bigWidth”:728,”bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
    Review the code. The entire code that animates the auto color change should look like this:

       <! DOCTYPE html > < html > < head > < style > body { -webkit- animation : cporchange 60 s infinite ; animation : cporchange 60 s infinite ; } @ -webkit-keyframes cporchange { 0 % { background : #33FFF3 ;} 25 % { background : #78281F ;} 50 % { background : #117A65 ;} 75 % { background : #DC7633 ;} 100 % { background : # 9B59B6 ;} } @ keyframes cporchange { 0 % { background : #33FFF3 ;} 25 % { background : #78281F ;} 50 % { background : #117A65 ;} 75 % { background : #DC7633 ;} 100 % { background : # 9B59B6 ; } } </style> < / head > <body> </body> < / html > _ _ _ 
  • Advice

    • If you want to use a base color in your HTML code, you can enter the color name without adding the pound sign (#) instead of using the HTML color code. For example, to make the background orange, you would type background-cpor: orange; here.
    • You can also use an image as the background of your web page using HTML.

    Warning

    • Test any changes to your website before applying online.
    X

    This article is co-authored by a team of editors and trained researchers who confirm the accuracy and completeness of the article.

    The wikiHow Content Management team carefully monitors the work of editors to ensure that every article is up to a high standard of quality.

    This article has been viewed 77,680 times.

    This is an article on how to change the background color of the web page by editing the HTML file.

    Thank you for reading this post How to Set Background Color in HTML at Tnhelearning.edu.vn You can comment, see more related articles below and hope to help you with interesting information.

    Related Search:

    Related Posts

    How to Create Curved Text in Photoshop
    How to fall asleep faster
    How to Install FBReader to Read eBooks

    Category: How To

    Previous Post: « Top 999+ trust quotes images – Amazing Collection trust quotes images Full 4K
    Next Post: Top 999+ Negan Wallpaper Full HD, 4K✅Free to Use »

    Copyright © 2025 · Tnhelearning.edu.vn - Useful Knowledge