How To's
8 min read

Learn HTML Basics: Changing Font Color, Size, and Type

Learn HTML with this beginner-friendly guide to changing font color, size, and type. Master simple steps to customize your web pages effortlessly!
Written by
Samruddhi
Published on
January 15, 2025

Are you ready to take the first step toward creating stunning, customized web pages? This guide is your ultimate resource for mastering the basics of HTML.

Whether you want to change font color, adjust font size, or experiment with different font types, we’ve got you covered. Did you know that over 94% of web pages use HTML in some form (source: W3Techs)?

With this guide, you'll learn simple techniques to transform plain text into visually engaging content. Let’s dive in and explore how you can make your web pages stand out, even as a beginner!

What Are HTML Tags and Attributes?

HTML tags and attributes are the building blocks of a web page. Tags tell the browser what each part of your content is, like <p> for a paragraph or <h1> for a heading.

Attributes, like the style attribute, give extra information about tags. For example, you can change color attribute a font color by adding style="color:red;" to your tag.

HTML font elements were widely used in earlier versions of HTML to style text, but CSS is now preferred for better flexibility. It’s simple and fun to try!


Step-by-Step Guide to Changing Font Color

Step-by-Step Guide to Changing Font Color
Step-by-Step Guide to Changing Font Color

Method 1: Using Inline Style Attribute

Inline styles are ideal for quick, one-off customizations, such as changing the font size of a single paragraph. Changing font color with the inline style attribute is quick and easy. Here’s how you can do it:

  • Pick the tag you want to style: For example, use a <p> tag to create a paragraph.
  • Add the style attribute: Inside the opening tag, type style=.
  • Set the font color: Write color: followed by the color name, hex code, or rgb value. For example: <p style="color: blue;">This is blue text.</p>
  • Save your file: Save your HTML file and open it in a browser to see the color change.

You can use this method for any tag, such as <h1> or <span>. Inline CSS is simple for quick changes but can get messy if overused.


Method 2: Using Internal CSS

Using internal CSS to change font color is a great way to style multiple elements in your HTML file. Here's how you can do it:

  • Start with a <style> tag: Add this tag inside the <head> section of your HTML document. This is where you’ll define all the styles.
  • Write your CSS rules: Inside the <style> tag, define a CSS selector (e.g., p for paragraphs or .example for a class) and set the color property. Example
<style> p { color: blue; } </style>
  • Apply the rules: Add your HTML elements, like this: <p>This is blue text styled with internal CSS.</p>
  • Save and view: Save your HTML file and open it in a browser. Your font color will now match the CSS rules you defined!

Using internal CSS keeps your styles organized while allowing quick updates. It’s perfect for small web pages with consistent styling needs.


Method 3: Using External CSS

Using external CSS is the best way to manage font color for large web pages. It keeps your code clean and organized. Here’s how you can do it:

  • Create a new CSS file: Open your code editor and save a new file with the .css extension, like styles.css.
  • Define the font color: Write your CSS rules in the file. For example:
p { color: blue; }

This sets all paragraph (<p>) text to blue. You can also use hex codes (#0000FF) or rgb values (rgb(0, 0, 255)).

  • Link the CSS file to your HTML document: Add the following line inside the <head> section of your HTML file: <link rel="stylesheet" href="styles.css">
  • Save and view: Save both files, open your HTML file in a browser, and see the font color change!

External CSS works great when you want to apply consistent styles across multiple pages, saving time and effort.


How to Adjust the Font Size in HTML

1. Using the Style Attribute (Inline CSS)

The style attribute is the easiest way to change font size directly in your HTML. Follow these steps:

  • Pick the HTML tag you want to style, such as <p> for a paragraph.
  • Add the style attribute to the opening tag.
  • Inside the style attribute, type font-size: followed by the size value (e.g., pixels, em, or percentages).
  • Example: <p style="font-size: 20px;">This text is 20 pixels in size.</p>
  • Save your HTML file and view it in a browser to see the change.

This method is great for quick adjustments, but it can get cluttered if used in multiple places.


2. Using CSS Classes (Internal or External CSS)

CSS is ideal for managing font sizes across a web page or multiple pages. Here’s how:

  • Define a class in CSS: Add a CSS rule in the <style> tag (for internal CSS) or in an external CSS file:
.large-text { font-size: 24px; }
  • Apply the class in HTML: Use the class attribute in your HTML tag: <p class="large-text">This text is large!</p>
  • Link an external CSS file (optional): Add this line inside the <head> section of your HTML: <link rel="stylesheet" href="styles.css">

CSS classes make your code more organized. Plus, you can easily update font sizes across your web page without editing multiple elements.


3. Using HTML <style> Tag for Global Styling

The <style> tag is a simple way to set font sizes for your entire web page. It keeps your code clean and helps you manage styles in one place. Here’s how to use it:

  • Add the <style> tag: Place it inside the <head> section of your HTML document.
<style> p { font-size: 18px; } </style>
  • Define global rules: Use CSS selectors like p for paragraphs or h1 for headings. These rules will apply to every matching element in your document.
  • Save and view: Save your HTML file and open it in a browser. All paragraphs will now have a font size of 18 pixels.

This method is great for creating consistent styles across your page.


4. Using Relative Units (%, em, rem)

Relative units are flexible and adapt to screen sizes. Here’s how they work:

1. Understand the units:

  • %: Based on the parent element’s font size.
  • em: Relative to the element's parent font size.
  • rem: Relative to the root element (<HTML>).

2. Write the CSS:

<style> p { font-size: 120%; /* 120% of the parent size */ } h1 { font-size: 2rem; /* Twice the root font size */ } </style>

3. Apply and view: Save and open your file to see the body text scale dynamically.

Relative units are ideal for responsive design, ensuring your text looks great on all devices. With these methods, you can control font sizes with ease and make your web pages more readable!

Choosing the right font size and color combinations significantly improves your website's readability


The Role of the CSS Color Property in Styling HTML Elements

The Role of the CSS Color Property in Styling HTML Elements
The Role of the CSS Color Property in Styling HTML Elements

The CSS color property is a crucial tool for changing the font color in HTML. It allows you to customize text colors to match darker color of your web page’s design and branding.

Whether you want your own text color to stand out in contrast or complement your overall layout, the color property makes it easy to achieve.

The color property is used to define the color of text in HTML. You can specify the color in different formats, such as color names (e.g., "blue"), hex codes (e.g., #0000FF), or RGB values (e.g., rgb(0, 0, 255)).

This flexibility enables you to choose from a wide range of colors, from basic shades of green and purple to specific tones that enhance your web page’s appearance.


How to Change Font Type in HTML

How to Change Font Type in HTML
How to Change Font Type in HTML

1. Using the style Attribute (Inline CSS)

This is the easiest way to set a font type for a specific element. Follow these steps:

  • Pick an HTML tag like <p> or <h1>.
  • Add the style attribute to the opening tag.
  • Inside the style attribute, use the font-family property and specify the font name. For example: <p style="font-family: Arial;">This text is in Arial font.</p>
  • Save your HTML file and open it in a browser to see the change.

This method is quick for small changes but can become messy if used in many places.


2. Using CSS Classes (Internal or External CSS)

CSS classes help you manage font styles for multiple elements in a clean way. Here’s how:

  • Create a CSS rule: Write a class in the <style> tag for internal CSS or an external CSS file.
.custom-font { font-family: "Times New Roman", serif; }
  • Apply the class in HTML: Add the class attribute to your element: <p class="custom-font">This text is in Times New Roman.</p>
  • Link an external CSS file (optional): Use this in the <head> section to link your .css file: <link rel="stylesheet" href="styles.css">

3. Using Web Fonts (Google Fonts)

Web fonts, like Google Fonts, let you use unique font styles that aren’t installed on a user’s device. They’re easy to use and enhance your web page’s design.

  • Choose a font on Google Fonts: Visit Google Fonts and pick a font you like. For example, select "Roboto."
  • Get the font link: Google Fonts provides a <link> tag to include in your HTML file. Copy this link and paste it inside the <head> section: <link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
  • Apply the font to your text: Use the font-family property in your CSS to style the text:

Using Google Fonts gives your website a professional and polished look while maintaining flexibility across devices.


4. Fallback Fonts

Fallback fonts are a backup plan for when a chosen font isn’t available on a user’s browser. You can list multiple fonts in the font-family property.

  • Define primary and fallback fonts: Specify your preferred font first, followed by generic alternatives: <p style="font-family: 'Arial', 'Helvetica', sans-serif;">This text uses Arial if available, or Helvetica as a fallback.</p>
  • Why use fallback fonts: Fallback fonts ensure your text is always displayed, even if the primary font isn’t supported. They improve the user experience by preventing issues with font loading.

By combining web fonts and fallback fonts, you can create stunning typography that works for all visitors.


How to Add a Background Color or Background Image to Pages

Adding a Background Color

1. Using Inline CSS

Inline CSS is a quick way to add a background color to specific elements. You can do this by adding the style attribute to an HTML tag and setting color values to the background-color property. For example: <p style="background-color: yellow;">This text has a yellow background.</p>

2. Using Internal CSS

Internal CSS allows you to manage styles in the <style> section of your HTML document. This keeps your code more organized. Example:

<head> <style> p { background-color: lightblue; } </style> </head> <body> <p>This text has a light blue background.</p> </body>

3. Using External CSS

For larger projects, external CSS is the best choice. Create a .css file, define your styles, and link it to your HTML file. Example:

CSS file (styles.css):

p { background-color: pink; }

HTML file:

<head> <link rel="stylesheet" href="styles.css"> </head> <body> <p>This text has a pink background.</p> </body>

Adding a Background Image

1. Using Inline CSS

Inline CSS is the quickest way to add a background image to a specific element. Use the style attribute within your HTML tag and set the background-image property. Here's an example:

<div style="background-image: url('background.jpg'); height: 200px; width: 100%;"> Your content here. </div>

This method is best for small-scale changes but can make your code less organized.

2. Using Internal CSS

Internal CSS lets you apply styles within the <style> section of your HTML document. This is ideal for managing multiple elements with a consistent background. Example:

<head> <style> body { background-image: url('background.jpg'); background-size: cover; background-repeat: no-repeat; } </style> </head> <body> Your content here. </body>

Internal CSS keeps your styles centralized in smaller projects.

3. Using External CSS

For larger projects, external CSS is the best choice. Define your background image in a .css file and link it to your HTML document. Example:

CSS file (styles.css):

body { background-image: url('background.jpg'); background-size: cover; background-repeat: no-repeat; }

HTML file:

<head> <link rel="stylesheet" href="styles.css"> </head> <body> Your content here. </body>

FAQs

1. Can I Use Gradient Backgrounds in HTML?

Yes, you can! Gradients create a smooth transition between colors. Use the CSS background property. For example: background: linear-gradient(to right, red, blue);

This creates a gradient that starts with red and ends with blue. Gradients are a great way to add depth to your web page design.

2. What are the Best Practices for Using Inline CSS?

Inline CSS is useful for quick changes, but don’t overuse it. Keep your HTML file clean by using external CSS for larger projects. Use inline CSS only when you need to style a single element directly. For example: <p style="color: blue; font-size: 16px;">Hello, world!</p>

It’s simple but not ideal for managing styles across many elements.

3. Can I Use Hex Codes for Background and Text Colors Together?

Absolutely! Hex codes let you specify precise colors for both text and backgrounds. Hexadecimal codes provide an exact representation of colors in HTML and CSS, making them indispensable for web design

For example: <p style="color: #ffffff; background-color: #000000;">White text on a black background</p>

This approach ensures your font color and background color match perfectly.


4. How Can I Make My Background Responsive?

To make your background responsive, use the background-size property in CSS. Set it to cover or contain. For instance:

background-size: cover;

background-repeat: no-repeat;

This ensures your image adapts to different screen sizes. Always pair dark text with light backgrounds to maintain excellent contrast and readability.

5. Can I Use Multiple Background Images?

Yes, you can use multiple background images in CSS by separating them with commas. For example: background: url('image1.jpg'), url('image2.png');

6. What is the Best Image Format for Backgrounds?

The best format depends on your use case. Use JPEG for photos, as it compresses well. For transparent backgrounds, choose PNG. If you need animations, go for GIF. Always optimize images to reduce page load time.

What is Alore?

Email Warmer

Generate real engagement to Warm Up Your Email Address without any human intervention

Drip Campaigner

Send emails that generate new business opprotunities for you

Collaborative Inbox

Improve team performance & customer experience - manage multiple email addresses from one place