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 div vertical scroll
- Create HTML button that looks like a href hyperlink
- Comprehensive 256 Ascii code table with Html Hex IBM Microsoft Key
- HTML5 HELLO WORLD Example
- Get HTML table td, tr or th inner content value with id or name attribute
- Adding Sub Headings to Bootstrap Header tags
- What is the doctype for HTML5?
- Chessboard with pieces using pure HTML and CSS
- Hyperlink in html (anchor tag) without a underline
- W3 : character data is not allowed here html validation error
- Fibonacci series from 1 to 500 table
- 9 Border to DIV Element in HTML Examples
- How to add multiple spaces between html page text
- How to turn off autocomplete in input fields in HTML Form
- Default speed of Marquee tag : SCROLLAMOUNT
- How to word wrap in HTML
- Force convert HTML text input to upper case
- HTML5 CSS3 Color Codes List
- How to remove old 404 pages ulrs from Google crawler
- reCaptcha Verification expired. Check the checkbox again
- All directional arrows codes for HTML
- Align html element at the center of page vertically and horizontally
- How to make a div tag clickable
- Remove Html head and body tags from ckeditor source
- Auto Refresh Webpage after every x Second or Minute using Meta Tag?
- How to initiate a photo request on iPhone from Mac Monterey - iOS
- Calculate discount amount python code - Python
- Failed to find provider info for com.facebook.katana.provider.PlatformProvider - Android
- Remove Trailing zeros BigDecimal Java - Java
- How to change directory in Git bash - Git
- [Solved] SharePoint Access Denied error editing Document Name - SharePoint
- Share Multiple Images in WhatsApp using Android Intent - WhatsApp
- Permanently Set or Change $JAVA_HOME on Mac (macOS) - MacOS