2.
Write a program in HTML using background colour and
text colour?
There are three methods to change the background color of a document:
Using bgcolor attribute
Using Inline CSS
Using Internal Stylesheet
<BODY bgcolor=”colorname”>
For example: <BODY bgcolor=”green”> or <BODY bgcolor=”blue”>
Method 1: Using bgcolor attribute
HTML provides various styles and attributes to make changes to the documents as
per the user’s needs. Following is an HTML code that shows the use
of bgcolor attribute:
<html >
<head>
<title>Document</title>
</head>
<body bgcolor="lightgreen" >
<h1>Hello reader my name is sachin Welcome to GeekforGeeks</h1>
</body>
</html>
Method 2: Using an Inline style attribute
If we want to change the color of a background of a web page using an inline style
attribute, we have to follow the steps which are given below. We can easily change
the color of the background from the following code:
<html >
<head>
<title>Internal CSS</title>
<style>
Body
{
background-color:greenyellow;
}
</style>
</head>
<body>
<h1>Welcome to GeeksforGeeks</h1>
<h2>We are using the Internal CSS</h2>
</body>
</html>
Method 3: Using internal CSS
If we want to change the color of a background of a web page using an internal
cascading stylesheet, we have to follow the steps which are given below. We can
easily change the background color from the following code:
<html lang="en">
<head>
<title>inline style attribute</title>
</head>
<body style="background-color:greenyellow">
<h1>Welcome to GeeksforGeeks</h1>
<h2>We are using the inline style attribute</h2>
</body>
</html>