CSS Introduction

CSS Tutorial What is CSS CSS Syntax CSS Selector How to include CSS CSS Comments

CSS Attributes

CSS Background CSS Border CSS Display CSS Float CSS Font CSS Color CSS Hover CSS Important CSS Line-height CSS Margin CSS Opacity CSS Filter CSS Images CSS Overflow CSS Padding CSS Position CSS Vertical align CSS White space CSS Width Word-wrap in CSS Box-shadow in CSS Text-transform in CSS CSS Outline CSS Visibility CSS Counters CSS Clear fix CSS Icons CSS Justify-content Text-decoration in CSS CSS Lists CSS nth selector CSS Sticky CSS Background-clip CSS Checkbox-style CSS Letter-spacing CSS Navigation bar CSS Overlay CSS Root CSS Specificity CSS Text-indent CSS Text-stroke CSS Zoom CSS Order CSS Descendent selector CSS Clip CSS calc() CSS Background-blend-mode CSS radio-button CSS Superscript and subscript CSS Text-effects CSS Text-align CSS Variables CSS Page-break-before CSS Page-break-inside CSS Page-break-after CSS Content property CSS Word-spacing CSS Animation CSS @keyframes rules CSS Pseudo-classes CSS Pseudo-elements CSS Radial-gradient CSS Translate CSS Gradients CSS z-index CSS Loaders CSS Units CSS Transition CSS Masking CSS Arrow CSS Pagination


What is Bootstrap CSS What is CSS used for Difference between HTML and CSS How to center a table in CSS What is a CSS File How to center a button in CSS How to change background color in CSS How to change the font in CSS How to change font size in CSS How to resize an image in CSS How to get rid of bullet pioints in CSS Is CSS a programming language Grid Vs Flexbox in CSS How to edit CSS in WordPress How to use google fonts in CSS

How to change the font in CSS

How to change the font in CSS?

Professionals can't deny typefaces — how users organize and style text — if we want to completely customize the website's design. One may wish to change the font's style, size, or color based on the designs, business, themes, specialty, and audience.

For example, if the color scheme favors dark grey over black, we want to adjust the text's default font color. We may use a sans serif font if we work in the media, which is usually the simplest to read type. A beautiful font like Morris Troy would be a better choice when we're in the creative area. These are a few reasons why one may wish to change the typeface on the website.

Identifying the right typeface has a massive effect on how visitors interact with a website.

The appropriate typeface can help you establish a powerful brand identity.

It is critical to have an easy-to-read typeface. Your text will be more valuable because of the typeface. It is also critical to select the appropriate font color and size.

Font Families:

There are five generic font families in CSS:

  1. Each letter in a serif font has a tiny stroke at the edge. They give off a stately and elegant vibe.
  2. Clean lines characterize sans-serif fonts (no small strokes attached). They give off a modern, minimalistic vibe.
  3. Monospace typefaces have the same set width for all letters. They give off a mechanical vibe.
  4. Cursive fonts are designed to seem like human handwriting.
  5. Fantasy typefaces are fun and decorative.

The various font names are members of one of the generic font families.

Begin with the typeface we desire to work down to a general collection (to let the browser know it has to select a similar font from the generic family if no other fonts are available). To achieve optimal interoperability amongst browsers/operating systems, the font-family field should hold many font names as a "fallback" mechanism. A comma should be used to separate the font names.

Syntax: -

font-family: “font_name”,”font_family_name”;

This CSS property is a shorthand property that combines the typefaces, font-variant, font-weight, font-stretch, font-size, line-height, and font-family sub-properties into a statement. In CSS, the font property is then used to manage the appearance of text. We may modify the font size, color, style, and more by using it.

The font size and font-family values of the abbreviated font property are required. If either of these attributes is missing, the declaration will be overlooked. The font-family value must likewise be declared last among all values; otherwise, the declaration will be neglected. The remaining five parameters are optional.

Font-style, font-variant, and font-weight must be stated before the declaration's font size if used in the font shorthand property. If they're not, they will be overlooked, resulting in a lack of understanding of necessary values.

The CSS Font property can be applied using inline CSS, internal CSS, or external CSS. Also, it can be applied to any HTML element like id, class, or tag.

We can also apply different font families and font-size to different HTML elements within the same HTML code.

Example: -

<!DOCTYPE html>
	font-family : "Brush Script MT","Cursive";
    font-size : 36px;
#id_time {
  font-family: "Georgia", Times, serif;
  font-size : 20px;
.class_arial {
  font-family: Arial, Verdana, sans-serif;
  font-size : 18px;
.mono {
  font-family: "Monaco","Lucida Console", "Courier New", monospace;
  font-size: 25px;
<h1>CSS font-family Example</h1>
<p id="id_time">This paragraph is an example of Georgia Font which belongs to serif family.</p>
<p class="class_arial">This paragraph is an example of Arial,Verdana Font which belongs to sans serif family</p>
<p class="mono">This his paragraph is an example of Lucida Console,Monaco,Courier New Font which belongs to sans serif family</p>
<h2>End Of example of Font Family</h2>

Output: -

How to change the font in CSS

So now let’s understand the above example. Here, we have applied different font styles to different elements of HTML.

As for h1, an h2 tag font from the cursive family with font-size 36px is applied.

The next paragraph tag, which has id id_time, has applied Georgia font from the serif font family with a font size of 20px.

For a paragraph which has a class named class_arial is applied with Arial, Verdana font from sans serif font family.

In the third paragraph, we have applied font Lucida Console, Monaco, Courier New for class mono which belongs to the sans serif font family.