CSS Fonts

CSS fonts allow you to control the typography of text in HTML elements. You can set the font family, size, weight, style, and apply custom web fonts for a consistent design.

Font Family

The font-family property specifies the font for text. You can provide multiple fonts as a fallback.

Example
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
  font-family: Arial, Helvetica, sans-serif;
}
</style>
</head>
<body>

<h1>Introduction CSS</h1>

</body>
</html>
Try this code

Font Size

The font-size property sets the size of the text. You can use pixels, em, rem, percentages, or keywords.

Example
<!DOCTYPE html>
<html>
<head>
<style>
p {
  font-size: 16px;
}
</style>
</head>
<body>

<p>Introduction CSS</p>

</body>
</html>
Try this code

Font Weight

The font-weight property defines the thickness of the text. Common values: normal, bold, lighter, or numeric values 100-900.

strong {
  font-weight: bold;
}

p.light {
  font-weight: 300;
}

Font Style

The font-style property sets the style of the text, such as normal, italic, or oblique.

em {
  font-style: italic;
}

p.oblique {
  font-style: oblique;
}

Custom Web Fonts

You can use @font-face to include custom fonts in your website.

@font-face {
  font-family: "MyCustomFont";
  src: url("MyCustomFont.woff2") format("woff2"),
       url("MyCustomFont.woff") format("woff");
}

p.custom {
  font-family: "MyCustomFont", sans-serif;
}

Best Practices for Fonts

Common Mistakes with Fonts

Tip: Combine font-family, font-size, and line-height to create clean and readable text designs.