Write a program to create a webpage to print your city name in red color.

Description: Create a web page that prints the name of your city in red colour.

Hint:

  • Use the style attribute with the CSS color property.
  • The old <font color="red"> tag is not valid in HTML5.

HTML program to print a city name in red

<!DOCTYPE html>
<html lang="en">
<head>
  <title>My City</title>
</head>
<body>
  <h1 style="color: red;">Delhi</h1>
</body>
</html>

Output in the browser:

Output in the browser

Delhi

How it works

  • The style attribute holds CSS for this element only.
  • color: red; changes the text colour to red. You can also use a hex code like #ff0000.

Learn more in HTML Styles.


Learn more about the similar topics:
Tutorials
HTML Elements and Tags
Exercises & Assignments
Write a program to create a webpage to print values 1 to 5
Write a program to create a webpage to print your city name in red color.
Write a program to print a paragraph with different font and color.
Interview Questions & Answers
Do all HTML tags require both a begin and end tag?