---
title: "How do you change the fonts of the webpage?"  
description: "How do you change the fonts of the webpage?"  
author: "Ravi Vishwakarma"  
published: 2024-06-05  
updated: 2024-06-05  
canonical: https://www.mindstick.com/interview/33886/how-do-you-change-the-fonts-of-the-webpage  
category: "css-css3"  
tags: ["css-css3", "css"]  
reading_time: 5 minutes  

---

# How do you change the fonts of the webpage?

Changing the fonts on a webpage involves specifying the desired font-family and other related properties such as font-size, font-weight, and font-style in your CSS. Here are the steps and different methods to achieve this:

### Basic Font Styling

1. **Using System Fonts**

You can use the default system fonts available on the user's device.

```html
body {
  font-family: Arial, sans-serif;
}

h1 {
  font-family: 'Times New Roman', serif;
}
```

### Importing Fonts

## Using Google Fonts

Google Fonts is a popular source of web fonts that you can easily integrate into your website.

- **Step 1**: Go to [Google Fonts](https://fonts.google.com/), select a font, and click on "Select this style".
- **Step 2**: Copy the provided `<link>` tag into the `<head>` of your HTML file.

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap">
  <style>
    body {
      font-family: 'Roboto', sans-serif;
    }
  </style>
</head>
<body>
  <h1>Hello, World!</h1>
</body>
</html>
```

## Using @font-face

You can also use the `@font-face` rule to include custom fonts stored on your server.

- **Step 1**: Upload the font files (e.g., `.woff`, `.woff2`, `.ttf`) to your server.
- **Step 2**: Define the font using `@font-face` in your CSS.

```css
@font-face {
  font-family: 'MyCustomFont';
  src: url('fonts/MyCustomFont.woff2') format('woff2'),
       url('fonts/MyCustomFont.woff') format('woff');
}

body {
  font-family: 'MyCustomFont', sans-serif;
}
```

### Font Properties

## Font Properties

You can use various CSS properties to fine-tune the font styling.

- **font-size**: Adjusts the size of the text.
- **font-weight**: Sets the weight (thickness) of the font.
- **font-style**: Sets the style of the font (normal, italic, oblique).
- **line-height**: Sets the height of lines of text.
- **letter-spacing**: Adjusts the space between characters.
- **text-transform**: Controls the capitalization of text (uppercase, lowercase, capitalize).

```css
p {
  font-size: 16px;
  font-weight: 400;
  font-style: italic;
  line-height: 1.5;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
```

### Example: Combining Everything

Here's an example combining different methods to change fonts and apply additional font properties:

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Font Styling Example</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&display=swap">
  <style>
    @font-face {
      font-family: 'MyCustomFont';
      src: url('fonts/MyCustomFont.woff2') format('woff2'),
           url('fonts/MyCustomFont.woff') format('woff');
    }

    body {
      font-family: 'Open Sans', sans-serif;
    }

    h1 {
      font-family: 'MyCustomFont', sans-serif;
      font-size: 2.5em;
      font-weight: 700;
    }

    p {
      font-size: 1em;
      font-weight: 400;
      line-height: 1.6;
      letter-spacing: 0.02em;
    }
  </style>
</head>
<body>
  <h1>Custom Font Heading</h1>
  <p>This is a paragraph with a Google font.</p>
</body>
</html>
```

## Answers

### Answer by Ravi Vishwakarma

Changing the fonts on a webpage involves specifying the desired font-family and other related properties such as font-size, font-weight, and font-style in your CSS. Here are the steps and different methods to achieve this:

### Basic Font Styling

1. **Using System Fonts**

You can use the default system fonts available on the user's device.

```html
body {
  font-family: Arial, sans-serif;
}

h1 {
  font-family: 'Times New Roman', serif;
}
```

### Importing Fonts

## Using Google Fonts

Google Fonts is a popular source of web fonts that you can easily integrate into your website.

- **Step 1**: Go to [Google Fonts](https://fonts.google.com/), select a font, and click on "Select this style".
- **Step 2**: Copy the provided `<link>` tag into the `<head>` of your HTML file.

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap">
  <style>
    body {
      font-family: 'Roboto', sans-serif;
    }
  </style>
</head>
<body>
  <h1>Hello, World!</h1>
</body>
</html>
```

## Using @font-face

You can also use the `@font-face` rule to include custom fonts stored on your server.

- **Step 1**: Upload the font files (e.g., `.woff`, `.woff2`, `.ttf`) to your server.
- **Step 2**: Define the font using `@font-face` in your CSS.

```css
@font-face {
  font-family: 'MyCustomFont';
  src: url('fonts/MyCustomFont.woff2') format('woff2'),
       url('fonts/MyCustomFont.woff') format('woff');
}

body {
  font-family: 'MyCustomFont', sans-serif;
}
```

### Font Properties

## Font Properties

You can use various CSS properties to fine-tune the font styling.

- **font-size**: Adjusts the size of the text.
- **font-weight**: Sets the weight (thickness) of the font.
- **font-style**: Sets the style of the font (normal, italic, oblique).
- **line-height**: Sets the height of lines of text.
- **letter-spacing**: Adjusts the space between characters.
- **text-transform**: Controls the capitalization of text (uppercase, lowercase, capitalize).

```css
p {
  font-size: 16px;
  font-weight: 400;
  font-style: italic;
  line-height: 1.5;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
```

### Example: Combining Everything

Here's an example combining different methods to change fonts and apply additional font properties:

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Font Styling Example</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&display=swap">
  <style>
    @font-face {
      font-family: 'MyCustomFont';
      src: url('fonts/MyCustomFont.woff2') format('woff2'),
           url('fonts/MyCustomFont.woff') format('woff');
    }

    body {
      font-family: 'Open Sans', sans-serif;
    }

    h1 {
      font-family: 'MyCustomFont', sans-serif;
      font-size: 2.5em;
      font-weight: 700;
    }

    p {
      font-size: 1em;
      font-weight: 400;
      line-height: 1.6;
      letter-spacing: 0.02em;
    }
  </style>
</head>
<body>
  <h1>Custom Font Heading</h1>
  <p>This is a paragraph with a Google font.</p>
</body>
</html>
```


---

Original Source: https://www.mindstick.com/interview/33886/how-do-you-change-the-fonts-of-the-webpage

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
