Write a program to print a paragraph with different font and color.

Description: Create a web page with a paragraph of 4 sentences. Each sentence should have a different font and colour.

Hint:

  • Put the paragraph in a <p> tag.
  • Wrap each sentence in a <span> and use font-family and color in the style attribute.

HTML program for a paragraph with different font and colour

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Fonts and colours</title>
</head>
<body>
  <p>
    <span style="font-family: Arial; color: red;">This sentence is in Arial and red.</span>
    <span style="font-family: 'Times New Roman'; color: green;">This one is in Times New Roman and green.</span>
    <span style="font-family: Verdana; color: blue;">This one is in Verdana and blue.</span>
    <span style="font-family: 'Courier New'; color: purple;">The last one is in Courier New and purple.</span>
  </p>
</body>
</html>

Output in the browser:

Output in the browser

This sentence is in Arial and red. This one is in Times New Roman and green. This one is in Verdana and blue. The last one is in Courier New and purple.

How it works

  • <span> is an inline tag, so all sentences stay in the same paragraph.
  • Each span has its own font-family and color.
  • Old tutorials use the <font> tag for this. It is removed from HTML5, so we use CSS.

See HTML Div and Span.


Learn more about the similar topics:
Tutorials
HTML Headings
HTML Paragraphs
HTML Styles
HTML Formatting
HTML Comments
HTML Symbols
Exercises & Assignments
Program to see difference between paragraphs & normal text with line break
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.
Write an HTML program to display all six heading levels
Write an HTML program for text formatting (bold, italic, subscript, superscript)
Interview Questions & Answers
How to add comments in HTML?
How to add the copyright symbol to a web page?
What is the difference between strong and b tag in HTML?
What are HTML entities?
What is the difference between inline, internal and external CSS?