HTML pages have a default while color background if you wish to use a specific color to your webpage here are different ways you can do it,
- Using bgcolor attribute in body tag:
- Using inline style CSS
- Using embedded CSS
- Using CSS class
- Using external CSS
⛏️ You will set the background color to the <body> tag.
1. Using bgcolor attribute in body tag:
This is a special attribute that you use in body tag that would change the color of your webpage as defined, there are multiple ways you can use it,
- Using color names: aqua, black, gray, fuchsia, white, maroon, olive, navy, teal, red, green, blue, purple, yellow, lime, silver e.t.c.
- Using hex # color codes: #f2f2f2, #eeeeee, #784264, #aa7722, #189d1920
- Using rgb color codes: rgb(128, 128, 128), rgb(0, 0, 0)
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML : bogy bgcolor Example</title>
</head>
<body bgcolor="green">
<p>Setting background-color to HTML webpage using bgcolor</p>
</body>
</html>
2. Using inline style CSS:
You can make use of inline style element to set background color using background-color property,
Example:<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML : background-color inline css Example</title>
</head>
<body style="background-color:#777777">
<p>Setting background-color to HTML webpage using background-color property</p>
</body>
</html>
3. Using embedded CSS:
This is one of the most preferred ways of setting a background for your webpage, just take the embedded style into a style element in your head section.
Example:<!DOCTYPE html>
<html lang="en">
<style>
body {
background-color:#cccccc;
}
</style>
<head>
<title>HTML : background-color embeded CSSExample</title>
</head>
<body>
<p>Setting background-color to HTML webpage using background-color property embeded CSS</p>
</body>
</html>
4. Using CSS class:
Example:<!DOCTYPE html>
<html lang="en">
<style>
.page-background {
background-color:#550055;
}
</style>
<head>
<title>HTML : background-color using CSS Class Example</title>
</head>
<body class="page-background">
<p>Setting background-color to HTML webpage using background-color property as a CSS class</p>
</body>
</html>
5. Using External CSS:
If you are using an external .css file then you just take the code in the style section to that file!
<!DOCTYPE html>
<html lang="en">
<link rel="stylesheet" type="text/css" href="style.css" />
<head>
<title>HTML : background-color using external CSS file Example</title>
</head>
<body>
<p>Setting background-color to HTML webpage using background-color using external CSS file.</p>
</body>
</html>
External style.css file:
body {
background-color:#eeefff;
}
⚡️ Supported by all browsers: Safari, Google Chrome, Internet Explorer, Opera, Firefox.
- Remove Html head and body tags from ckeditor source
- Default speed of Marquee tag : SCROLLAMOUNT
- Align html element at the center of page vertically and horizontally
- HTML, HTML5. CSS, CSS3 Color Codes 2020
- How to add multiple spaces between html page text
- Force convert HTML text input to upper case
- Obsolete marquee element alternatives html5
- How to set background color in HTML page?
- Base 64 Index, Character and Binary Table
- Hyperlink in html (anchor tag) without a underline
- How to remove old 404 pages ulrs from Google crawler
- W3 HTML validator warning Unable to Determine Parse Mode
- Get HTML table td, tr or th inner content value with id or name attribute
- How to word wrap in HTML
- reCaptcha Verification expired. Check the checkbox again
- Adding Sub Headings to Bootstrap Header tags
- Chessboard with pieces using pure HTML and CSS
- How to turn off autocomplete in input fields in HTML Form
- All directional arrows codes for HTML
- Fibonacci series from 1 to 500 table
- W3 : character data is not allowed here html validation error
- How to make a div tag clickable
- Comprehensive 256 Ascii code table with Html Hex IBM Microsoft Key
- HTML5 HELLO WORLD Example
- Create HTML button that looks like a href hyperlink
- Indent Python code in Notepad++ - Python
- Find Java JRE Installation location Mac OS X - Mac-OS-X
- Android : java.lang.IllegalArgumentException File contains a path separator - Android
- Read and Parse XML file using Java DOM Parser [Java Tutorial] - Java
- How to fix java.net.NoRouteToHostException in Android Studio - Android-Studio
- pip get list of all outdated Python packages - Python
- iOS Fix: This app is no longer shared with you. To use it, you must buy it from the App Store. - Apple
- [Gmail] Calling in Hangouts will be turned off soon. - News