You are viewing the article How to Set Background Color in HTML at Lassho.edu.vn you can quickly access the necessary information in the table of contents of the article below.
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.
Steps
Prepare Before Editing HTML
- 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.
- You can use Notepad++ or Notepad on a Windows computer, or use TextEdit or BBEdit on a Mac computer.
<style></style>
tag:
<! DOCTYPE html > < html > < head > < style > </ style > </ head > </ html >
<style>
tag and above the </style>
tag. <style></style>
tag:
- Changes to the “body” part of the CSS will affect the entire page.
- Skip this step if you want to create a gradient background.
body { }
Create a solid color background
background-cpor:
in the brackets of the page body. You should now have a “body” section like this:
- Here you can only type “cpor” because typing “cpour” will fail.
body { background-cpor : }
body { background-cpor : #d24dff ; }
<! DOCTYPE html > < html > < head > < style > body { background-cpor : #d24dff } </ style > </ head > </ html >
<! 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
background : linear-gradient ( direction / angle , cpor1 , cpor2 , cpor3 , etc. );
<style></style>
tag:
- Each browser has a different way of displaying gradient color functionality, so you need to add more styles of commands.
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 ; }
<style></style>
tag: [4] X Research Source
- You can use the “left” (left) and “right” (right) tags to try out gradients in a different direction.
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 ; }
- 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 %);
background : linear-gradient ( to right , rgba ( 147 , 184 , 116 , 0 ), rgba ( 147 , 184 , 116 , 1 ));
<! 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
- The first line of the code is for open source browsers, and the last line of the code is for other browsers.
-webkit-animation : cporchange 60s infinite ; animation : cporchange 60s infinite ;
- 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.
@ -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 ;} }
<! 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.
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 Lassho.edu.vn You can comment, see more related articles below and hope to help you with interesting information.
Related Search: