Adding background color to text in html

Содержание
  1. Background Color
  2. The background-color Property
  3. Text and Background Color
  4. The background Property
  5. Background Images
  6. HTML Styles
  7. Example
  8. The HTML Style Attribute
  9. Background Color
  10. Example
  11. This is a heading
  12. Example
  13. This is a heading This is a paragraph.
  14. Text Color
  15. Example
  16. This is a heading This is a paragraph. Fonts The CSS font-family property defines the font to be used for an HTML element: Example This is a heading This is a paragraph. Text Size The CSS font-size property defines the text size for an HTML element: Example This is a heading This is a paragraph. Text Alignment The CSS text-align property defines the horizontal text alignment for an HTML element: Example Centered Heading Centered paragraph. Chapter Summary Use the style attribute for styling HTML elements Use background-color for background color Use color for text colors Use font-family for text fonts Use font-size for text sizes Use text-align for text alignment HTML Exercises COLOR PICKER Report Error If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail: Thank You For Helping Us! Your message has been sent to W3Schools. Top Tutorials Top References Top Examples Get Certified W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy. Источник 3 Methods to Set a Background Color with HTML & CSS This article was co-authored by wikiHow staff writer, Darlene Antonelli, MA. Darlene Antonelli is a Technology Writer and Editor for wikiHow. Darlene has experience teaching college courses, writing technology-related articles, and working hands-on in the technology field. She earned an MA in Writing from Rowan University in 2012 and wrote her thesis on online communities and the personalities curated in such communities. This article has been viewed 1,504,476 times. Did you want to change the background color of that page using HTML? Unfortunately, with HTML 5, this is no longer possible in just HTML coding. Instead, you’ll need to use both HTML and CSS coding, which works even better. This wikiHow teaches you how to change the background color of a web page by editing its HTML and CSS. Although the attribute for HTML to manage background color is gone, you can still use HTML with CSS to change your background color easily. You’ll need a numeric code for the color you want if you want a specific color. If you don’t need a specific color, you can use words like «orange» or «light blue.» When editing a web page with HTML and CSS, you can create a solid background, gradient, or changing background. Setting a Solid Background Color body background-color : #d24dff ; > DOCTYPE html > html > head > style > body background-color : #d24dff > style > head > html > DOCTYPE html > html > head > style > body background-color : #93B874 ; > h1 background-color : #00b33c ; > p background-color : #FFFFFF ); > style > head > body > h1 > Header with Green Background h1 > p > Paragraph with white background p > body > html > Creating a Gradient Background Understand the basic syntax of this process. When making a gradient, there are two pieces of information you’ll need: the starting point/angle, and the colors that the gradient will transition between. You can select multiple colors to have the gradient move between all of them, and you can set a direction or angle for the gradient. [2] X Research source background : linear-gradient ( direction / angle , color1 , color2 , color3 , etc ); 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-color : #93B874 ; > 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-color : #93B874 ; > For example, not only can you add more than two colors, you can also put a percentage after each one. This will allow you to set how much spacing you want each color segment to have. Here’s a sample gradient that uses 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-color : #93B874 ; > style > head > body > body > html > Creating a Changing Background -webkit-animation : colorchange 60s infinite ; animation : colorchange 60s infinite ; @ -webkit-keyframes colorchange 0 % background : #33FFF3 ;> 25 % background : #78281F ;> 50 % background : #117A65 ;> 75 % background : #DC7633 ;> 100 % background : #9B59B6 ;> > @ keyframes colorchange 0 % background : #33FFF3 ;> 25 % background : #78281F ;> 50 % background : #117A65 ;> 75 % background : #DC7633 ;> 100 % background : #9B59B6 ;> > DOCTYPE html > html > head > style > body -webkit- animation : colorchange 60 s infinite ; animation : colorchange 60 s infinite ; > @ -webkit-keyframes colorchange 0 % background : #33FFF3 ;> 25 % background : #78281F ;> 50 % background : #117A65 ;> 75 % background : #DC7633 ;> 100 % background : #9B59B6 ;> > @ keyframes colorchange 0 % background : #33FFF3 ;> 25 % background : #78281F ;> 50 % background : #117A65 ;> 75 % background : #DC7633 ;> 100 % background : #9B59B6 ;> > style > head > body > body > html > Community Q&A Use the background-size property inside of the «body» element. For example, «background-size: 300px 150px» makes the background 300 pixels wide and 150 pixels high. Thanks! We’re glad this was helpful. Thank you for your feedback. As a small thank you, we’d like to offer you a $30 gift card (valid at GoNift.com). Use it to try out great new products and services nationwide without paying full price—wine, food delivery, clothing and more. Enjoy! Claim Your Gift If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even $1 helps us in our mission. Support wikiHow Thanks! We’re glad this was helpful. Thank you for your feedback. As a small thank you, we’d like to offer you a $30 gift card (valid at GoNift.com). Use it to try out great new products and services nationwide without paying full price—wine, food delivery, clothing and more. Enjoy! Claim Your Gift If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even $1 helps us in our mission. Support wikiHow Thanks! We’re glad this was helpful. Thank you for your feedback. As a small thank you, we’d like to offer you a $30 gift card (valid at GoNift.com). Use it to try out great new products and services nationwide without paying full price—wine, food delivery, clothing and more. Enjoy! Claim Your Gift If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even $1 helps us in our mission. Support wikiHow Источник
  17. Fonts
  18. Example
  19. This is a heading This is a paragraph. Text Size The CSS font-size property defines the text size for an HTML element: Example This is a heading This is a paragraph. Text Alignment The CSS text-align property defines the horizontal text alignment for an HTML element: Example Centered Heading Centered paragraph. Chapter Summary Use the style attribute for styling HTML elements Use background-color for background color Use color for text colors Use font-family for text fonts Use font-size for text sizes Use text-align for text alignment HTML Exercises COLOR PICKER Report Error If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail: Thank You For Helping Us! Your message has been sent to W3Schools. Top Tutorials Top References Top Examples Get Certified W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy. Источник 3 Methods to Set a Background Color with HTML & CSS This article was co-authored by wikiHow staff writer, Darlene Antonelli, MA. Darlene Antonelli is a Technology Writer and Editor for wikiHow. Darlene has experience teaching college courses, writing technology-related articles, and working hands-on in the technology field. She earned an MA in Writing from Rowan University in 2012 and wrote her thesis on online communities and the personalities curated in such communities. This article has been viewed 1,504,476 times. Did you want to change the background color of that page using HTML? Unfortunately, with HTML 5, this is no longer possible in just HTML coding. Instead, you’ll need to use both HTML and CSS coding, which works even better. This wikiHow teaches you how to change the background color of a web page by editing its HTML and CSS. Although the attribute for HTML to manage background color is gone, you can still use HTML with CSS to change your background color easily. You’ll need a numeric code for the color you want if you want a specific color. If you don’t need a specific color, you can use words like «orange» or «light blue.» When editing a web page with HTML and CSS, you can create a solid background, gradient, or changing background. Setting a Solid Background Color body background-color : #d24dff ; > DOCTYPE html > html > head > style > body background-color : #d24dff > style > head > html > DOCTYPE html > html > head > style > body background-color : #93B874 ; > h1 background-color : #00b33c ; > p background-color : #FFFFFF ); > style > head > body > h1 > Header with Green Background h1 > p > Paragraph with white background p > body > html > Creating a Gradient Background Understand the basic syntax of this process. When making a gradient, there are two pieces of information you’ll need: the starting point/angle, and the colors that the gradient will transition between. You can select multiple colors to have the gradient move between all of them, and you can set a direction or angle for the gradient. [2] X Research source background : linear-gradient ( direction / angle , color1 , color2 , color3 , etc ); 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-color : #93B874 ; > 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-color : #93B874 ; > For example, not only can you add more than two colors, you can also put a percentage after each one. This will allow you to set how much spacing you want each color segment to have. Here’s a sample gradient that uses 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-color : #93B874 ; > style > head > body > body > html > Creating a Changing Background -webkit-animation : colorchange 60s infinite ; animation : colorchange 60s infinite ; @ -webkit-keyframes colorchange 0 % background : #33FFF3 ;> 25 % background : #78281F ;> 50 % background : #117A65 ;> 75 % background : #DC7633 ;> 100 % background : #9B59B6 ;> > @ keyframes colorchange 0 % background : #33FFF3 ;> 25 % background : #78281F ;> 50 % background : #117A65 ;> 75 % background : #DC7633 ;> 100 % background : #9B59B6 ;> > DOCTYPE html > html > head > style > body -webkit- animation : colorchange 60 s infinite ; animation : colorchange 60 s infinite ; > @ -webkit-keyframes colorchange 0 % background : #33FFF3 ;> 25 % background : #78281F ;> 50 % background : #117A65 ;> 75 % background : #DC7633 ;> 100 % background : #9B59B6 ;> > @ keyframes colorchange 0 % background : #33FFF3 ;> 25 % background : #78281F ;> 50 % background : #117A65 ;> 75 % background : #DC7633 ;> 100 % background : #9B59B6 ;> > style > head > body > body > html > Community Q&A Use the background-size property inside of the «body» element. For example, «background-size: 300px 150px» makes the background 300 pixels wide and 150 pixels high. Thanks! We’re glad this was helpful. Thank you for your feedback. As a small thank you, we’d like to offer you a $30 gift card (valid at GoNift.com). Use it to try out great new products and services nationwide without paying full price—wine, food delivery, clothing and more. Enjoy! Claim Your Gift If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even $1 helps us in our mission. Support wikiHow Thanks! We’re glad this was helpful. Thank you for your feedback. As a small thank you, we’d like to offer you a $30 gift card (valid at GoNift.com). Use it to try out great new products and services nationwide without paying full price—wine, food delivery, clothing and more. Enjoy! Claim Your Gift If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even $1 helps us in our mission. Support wikiHow Thanks! We’re glad this was helpful. Thank you for your feedback. As a small thank you, we’d like to offer you a $30 gift card (valid at GoNift.com). Use it to try out great new products and services nationwide without paying full price—wine, food delivery, clothing and more. Enjoy! Claim Your Gift If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even $1 helps us in our mission. Support wikiHow Источник
  20. Text Size
  21. Example
  22. This is a heading This is a paragraph. Text Alignment The CSS text-align property defines the horizontal text alignment for an HTML element: Example Centered Heading Centered paragraph. Chapter Summary Use the style attribute for styling HTML elements Use background-color for background color Use color for text colors Use font-family for text fonts Use font-size for text sizes Use text-align for text alignment HTML Exercises COLOR PICKER Report Error If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail: Thank You For Helping Us! Your message has been sent to W3Schools. Top Tutorials Top References Top Examples Get Certified W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy. Источник 3 Methods to Set a Background Color with HTML & CSS This article was co-authored by wikiHow staff writer, Darlene Antonelli, MA. Darlene Antonelli is a Technology Writer and Editor for wikiHow. Darlene has experience teaching college courses, writing technology-related articles, and working hands-on in the technology field. She earned an MA in Writing from Rowan University in 2012 and wrote her thesis on online communities and the personalities curated in such communities. This article has been viewed 1,504,476 times. Did you want to change the background color of that page using HTML? Unfortunately, with HTML 5, this is no longer possible in just HTML coding. Instead, you’ll need to use both HTML and CSS coding, which works even better. This wikiHow teaches you how to change the background color of a web page by editing its HTML and CSS. Although the attribute for HTML to manage background color is gone, you can still use HTML with CSS to change your background color easily. You’ll need a numeric code for the color you want if you want a specific color. If you don’t need a specific color, you can use words like «orange» or «light blue.» When editing a web page with HTML and CSS, you can create a solid background, gradient, or changing background. Setting a Solid Background Color body background-color : #d24dff ; > DOCTYPE html > html > head > style > body background-color : #d24dff > style > head > html > DOCTYPE html > html > head > style > body background-color : #93B874 ; > h1 background-color : #00b33c ; > p background-color : #FFFFFF ); > style > head > body > h1 > Header with Green Background h1 > p > Paragraph with white background p > body > html > Creating a Gradient Background Understand the basic syntax of this process. When making a gradient, there are two pieces of information you’ll need: the starting point/angle, and the colors that the gradient will transition between. You can select multiple colors to have the gradient move between all of them, and you can set a direction or angle for the gradient. [2] X Research source background : linear-gradient ( direction / angle , color1 , color2 , color3 , etc ); 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-color : #93B874 ; > 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-color : #93B874 ; > For example, not only can you add more than two colors, you can also put a percentage after each one. This will allow you to set how much spacing you want each color segment to have. Here’s a sample gradient that uses 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-color : #93B874 ; > style > head > body > body > html > Creating a Changing Background -webkit-animation : colorchange 60s infinite ; animation : colorchange 60s infinite ; @ -webkit-keyframes colorchange 0 % background : #33FFF3 ;> 25 % background : #78281F ;> 50 % background : #117A65 ;> 75 % background : #DC7633 ;> 100 % background : #9B59B6 ;> > @ keyframes colorchange 0 % background : #33FFF3 ;> 25 % background : #78281F ;> 50 % background : #117A65 ;> 75 % background : #DC7633 ;> 100 % background : #9B59B6 ;> > DOCTYPE html > html > head > style > body -webkit- animation : colorchange 60 s infinite ; animation : colorchange 60 s infinite ; > @ -webkit-keyframes colorchange 0 % background : #33FFF3 ;> 25 % background : #78281F ;> 50 % background : #117A65 ;> 75 % background : #DC7633 ;> 100 % background : #9B59B6 ;> > @ keyframes colorchange 0 % background : #33FFF3 ;> 25 % background : #78281F ;> 50 % background : #117A65 ;> 75 % background : #DC7633 ;> 100 % background : #9B59B6 ;> > style > head > body > body > html > Community Q&A Use the background-size property inside of the «body» element. For example, «background-size: 300px 150px» makes the background 300 pixels wide and 150 pixels high. Thanks! We’re glad this was helpful. Thank you for your feedback. As a small thank you, we’d like to offer you a $30 gift card (valid at GoNift.com). Use it to try out great new products and services nationwide without paying full price—wine, food delivery, clothing and more. Enjoy! Claim Your Gift If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even $1 helps us in our mission. Support wikiHow Thanks! We’re glad this was helpful. Thank you for your feedback. As a small thank you, we’d like to offer you a $30 gift card (valid at GoNift.com). Use it to try out great new products and services nationwide without paying full price—wine, food delivery, clothing and more. Enjoy! Claim Your Gift If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even $1 helps us in our mission. Support wikiHow Thanks! We’re glad this was helpful. Thank you for your feedback. As a small thank you, we’d like to offer you a $30 gift card (valid at GoNift.com). Use it to try out great new products and services nationwide without paying full price—wine, food delivery, clothing and more. Enjoy! Claim Your Gift If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even $1 helps us in our mission. Support wikiHow Источник
  23. Text Alignment
  24. Example
  25. Centered Heading Centered paragraph. Chapter Summary Use the style attribute for styling HTML elements Use background-color for background color Use color for text colors Use font-family for text fonts Use font-size for text sizes Use text-align for text alignment HTML Exercises COLOR PICKER Report Error If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail: Thank You For Helping Us! Your message has been sent to W3Schools. Top Tutorials Top References Top Examples Get Certified W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy. Источник 3 Methods to Set a Background Color with HTML & CSS This article was co-authored by wikiHow staff writer, Darlene Antonelli, MA. Darlene Antonelli is a Technology Writer and Editor for wikiHow. Darlene has experience teaching college courses, writing technology-related articles, and working hands-on in the technology field. She earned an MA in Writing from Rowan University in 2012 and wrote her thesis on online communities and the personalities curated in such communities. This article has been viewed 1,504,476 times. Did you want to change the background color of that page using HTML? Unfortunately, with HTML 5, this is no longer possible in just HTML coding. Instead, you’ll need to use both HTML and CSS coding, which works even better. This wikiHow teaches you how to change the background color of a web page by editing its HTML and CSS. Although the attribute for HTML to manage background color is gone, you can still use HTML with CSS to change your background color easily. You’ll need a numeric code for the color you want if you want a specific color. If you don’t need a specific color, you can use words like «orange» or «light blue.» When editing a web page with HTML and CSS, you can create a solid background, gradient, or changing background. Setting a Solid Background Color body background-color : #d24dff ; > DOCTYPE html > html > head > style > body background-color : #d24dff > style > head > html > DOCTYPE html > html > head > style > body background-color : #93B874 ; > h1 background-color : #00b33c ; > p background-color : #FFFFFF ); > style > head > body > h1 > Header with Green Background h1 > p > Paragraph with white background p > body > html > Creating a Gradient Background Understand the basic syntax of this process. When making a gradient, there are two pieces of information you’ll need: the starting point/angle, and the colors that the gradient will transition between. You can select multiple colors to have the gradient move between all of them, and you can set a direction or angle for the gradient. [2] X Research source background : linear-gradient ( direction / angle , color1 , color2 , color3 , etc ); 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-color : #93B874 ; > 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-color : #93B874 ; > For example, not only can you add more than two colors, you can also put a percentage after each one. This will allow you to set how much spacing you want each color segment to have. Here’s a sample gradient that uses 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-color : #93B874 ; > style > head > body > body > html > Creating a Changing Background -webkit-animation : colorchange 60s infinite ; animation : colorchange 60s infinite ; @ -webkit-keyframes colorchange 0 % background : #33FFF3 ;> 25 % background : #78281F ;> 50 % background : #117A65 ;> 75 % background : #DC7633 ;> 100 % background : #9B59B6 ;> > @ keyframes colorchange 0 % background : #33FFF3 ;> 25 % background : #78281F ;> 50 % background : #117A65 ;> 75 % background : #DC7633 ;> 100 % background : #9B59B6 ;> > DOCTYPE html > html > head > style > body -webkit- animation : colorchange 60 s infinite ; animation : colorchange 60 s infinite ; > @ -webkit-keyframes colorchange 0 % background : #33FFF3 ;> 25 % background : #78281F ;> 50 % background : #117A65 ;> 75 % background : #DC7633 ;> 100 % background : #9B59B6 ;> > @ keyframes colorchange 0 % background : #33FFF3 ;> 25 % background : #78281F ;> 50 % background : #117A65 ;> 75 % background : #DC7633 ;> 100 % background : #9B59B6 ;> > style > head > body > body > html > Community Q&A Use the background-size property inside of the «body» element. For example, «background-size: 300px 150px» makes the background 300 pixels wide and 150 pixels high. Thanks! We’re glad this was helpful. Thank you for your feedback. As a small thank you, we’d like to offer you a $30 gift card (valid at GoNift.com). Use it to try out great new products and services nationwide without paying full price—wine, food delivery, clothing and more. Enjoy! Claim Your Gift If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even $1 helps us in our mission. Support wikiHow Thanks! We’re glad this was helpful. Thank you for your feedback. As a small thank you, we’d like to offer you a $30 gift card (valid at GoNift.com). Use it to try out great new products and services nationwide without paying full price—wine, food delivery, clothing and more. Enjoy! Claim Your Gift If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even $1 helps us in our mission. Support wikiHow Thanks! We’re glad this was helpful. Thank you for your feedback. As a small thank you, we’d like to offer you a $30 gift card (valid at GoNift.com). Use it to try out great new products and services nationwide without paying full price—wine, food delivery, clothing and more. Enjoy! Claim Your Gift If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even $1 helps us in our mission. Support wikiHow Источник
  26. Chapter Summary
  27. HTML Exercises
  28. COLOR PICKER
  29. Report Error
  30. Thank You For Helping Us!
  31. 3 Methods to Set a Background Color with HTML & CSS
  32. Setting a Solid Background Color
  33. Creating a Gradient Background
  34. Creating a Changing Background
  35. Community Q&A
Читайте также:  Python прочитать txt файл построчно

Background Color

This page contains HTML background color code. Using this code, you can add a background color to any HTML element.

To add background color to an HTML element, you need to use the CSS background-color property. You can also use the background property, which allows/requires you to add other background related properties at the same time.

Here are some examples of applying background color to an HTML document.

The background-color Property

The CSS background-color property allows you to apply background color to an HTML element. In the following example, we apply background color to a div element. To demonstrate the example, we place some text within the element and color it black. We also add a black border around the using the border property.

Text and Background Color

You aren’t limited to applying background color to the div element. You can apply it to any HTML element. For example, background color is sometimes applied to a large or small section of text. You can use the element to pick a section of your text to highlight with a different color.

HTML text background color example

The background Property

As mentioned, the CSS background property allows you to add all your background related properties all in one go.

This is more efficient, especially if you’re applying many background properties.

Here’s an example of using the background property.

Background Images

You can also apply background color by using a background image. This will also allow you to add some «texture» to your background color, or even a background pattern. But even if you do use a background image, it’s good practice to use a background color as well. This ensures that, in the event your background image can’t be displayed, the background image will still display.

Читайте также:  Питон рекурсивные функции задачи

Источник

HTML Styles

The HTML style attribute is used to add styles to an element, such as color, font, size, and more.

Example

The HTML Style Attribute

Setting the style of an HTML element, can be done with the style attribute.

The HTML style attribute has the following syntax:

The property is a CSS property. The value is a CSS value.

You will learn more about CSS later in this tutorial.

Background Color

The CSS background-color property defines the background color for an HTML element.

Example

Set the background color for a page to powderblue:

This is a heading

This is a paragraph.

Example

Set background color for two different elements:

This is a heading

This is a paragraph.

Text Color

The CSS color property defines the text color for an HTML element:

Example

This is a heading

This is a paragraph.

Fonts

The CSS font-family property defines the font to be used for an HTML element:

Example

This is a heading

This is a paragraph.

Text Size

The CSS font-size property defines the text size for an HTML element:

Example

This is a heading

This is a paragraph.

Text Alignment

The CSS text-align property defines the horizontal text alignment for an HTML element:

Example

Centered Heading

Centered paragraph.

Chapter Summary

  • Use the style attribute for styling HTML elements
  • Use background-color for background color
  • Use color for text colors
  • Use font-family for text fonts
  • Use font-size for text sizes
  • Use text-align for text alignment

HTML Exercises

Unlock Full Access 50% off

COLOR PICKER

colorpicker

Join our Bootcamp!

Report Error

If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:

Thank You For Helping Us!

Your message has been sent to W3Schools.

Top Tutorials
Top References
Top Examples
Get Certified

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Источник

3 Methods to Set a Background Color with HTML & CSS

This article was co-authored by wikiHow staff writer, Darlene Antonelli, MA. Darlene Antonelli is a Technology Writer and Editor for wikiHow. Darlene has experience teaching college courses, writing technology-related articles, and working hands-on in the technology field. She earned an MA in Writing from Rowan University in 2012 and wrote her thesis on online communities and the personalities curated in such communities.

This article has been viewed 1,504,476 times.

Did you want to change the background color of that page using HTML? Unfortunately, with HTML 5, this is no longer possible in just HTML coding. Instead, you’ll need to use both HTML and CSS coding, which works even better. This wikiHow teaches you how to change the background color of a web page by editing its HTML and CSS.

  • Although the attribute for HTML to manage background color is gone, you can still use HTML with CSS to change your background color easily.
  • You’ll need a numeric code for the color you want if you want a specific color. If you don’t need a specific color, you can use words like «orange» or «light blue.»
  • When editing a web page with HTML and CSS, you can create a solid background, gradient, or changing background.

Setting a Solid Background Color

Image titled 2609629 1 3

Image titled 2609629 2 3

Image titled 2609629 3 3

body  background-color: #d24dff; > 

Image titled 2609629 4 3

DOCTYPE html> html> head> style> body  background-color: #d24dff > style> head> html> 

Image titled 2609629 5 3

DOCTYPE html> html> head> style> body  background-color: #93B874; > h1  background-color: #00b33c; > p  background-color: #FFFFFF); > style> head> body> h1>Header with Green Backgroundh1> p>Paragraph with white backgroundp> body> html> 

Creating a Gradient Background

Image titled 2609629 6 3

Image titled 2609629 7 3

Understand the basic syntax of this process. When making a gradient, there are two pieces of information you’ll need: the starting point/angle, and the colors that the gradient will transition between. You can select multiple colors to have the gradient move between all of them, and you can set a direction or angle for the gradient. [2] X Research source

background: linear-gradient(direction/angle, color1, color2, color3, etc); 

Image titled 2609629 8 4

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-color: #93B874; > 

Image titled 2609629 9 3

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-color: #93B874; > 

Image titled 2609629 10 3

    For example, not only can you add more than two colors, you can also put a percentage after each one. This will allow you to set how much spacing you want each color segment to have. Here’s a sample gradient that uses this principle:
background: linear-gradient(#93B874 10%, #C9DCB9 70%, #000000 90%); 

Image titled 2609629 11 3

background: linear-gradient(to right, rgba(147,184,116,0), rgba(147,184,116,1)); 

Image titled 2609629 12 3

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-color: #93B874; > style> head> body> body> html> 

Creating a Changing Background

Image titled 2609629 13 3

Image titled 2609629 14 3

-webkit-animation: colorchange 60s infinite; animation: colorchange 60s infinite; 

Image titled 2609629 15 3

@-webkit-keyframes colorchange  0% background: #33FFF3;> 25% background: #78281F;> 50% background: #117A65;> 75% background: #DC7633;> 100% background: #9B59B6;> > @keyframes colorchange  0% background: #33FFF3;> 25% background: #78281F;> 50% background: #117A65;> 75% background: #DC7633;> 100% background: #9B59B6;> > 

Image titled 2609629 16 3

DOCTYPE html> html> head> style> body  -webkit-animation: colorchange 60s infinite; animation: colorchange 60s infinite; > @-webkit-keyframes colorchange  0% background: #33FFF3;> 25% background: #78281F;> 50% background: #117A65;> 75% background: #DC7633;> 100% background: #9B59B6;> > @keyframes colorchange  0% background: #33FFF3;> 25% background: #78281F;> 50% background: #117A65;> 75% background: #DC7633;> 100% background: #9B59B6;> > style> head> body> body> html> 

Community Q&A

Use the background-size property inside of the «body» element. For example, «background-size: 300px 150px» makes the background 300 pixels wide and 150 pixels high.

Thanks! We’re glad this was helpful.
Thank you for your feedback.
As a small thank you, we’d like to offer you a $30 gift card (valid at GoNift.com). Use it to try out great new products and services nationwide without paying full price—wine, food delivery, clothing and more. Enjoy! Claim Your Gift If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even $1 helps us in our mission. Support wikiHow

Thanks! We’re glad this was helpful.
Thank you for your feedback.
As a small thank you, we’d like to offer you a $30 gift card (valid at GoNift.com). Use it to try out great new products and services nationwide without paying full price—wine, food delivery, clothing and more. Enjoy! Claim Your Gift If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even $1 helps us in our mission. Support wikiHow

Thanks! We’re glad this was helpful.
Thank you for your feedback.
As a small thank you, we’d like to offer you a $30 gift card (valid at GoNift.com). Use it to try out great new products and services nationwide without paying full price—wine, food delivery, clothing and more. Enjoy! Claim Your Gift If wikiHow has helped you, please consider a small contribution to support us in helping more readers like you. We’re committed to providing the world with free how-to resources, and even $1 helps us in our mission. Support wikiHow

Источник

Оцените статью