×

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>
<html>
<head>
<style>
h1,h2
{
	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;
}
</style>
</head>
<body>
<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>
</body>
</html>

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.


Related Topics

CSS Overlay

CSS Overlay: It measures to cover-up something’s surface along with a coating. CSS overlay sets anything over the top area of other things. It creates a web-page more attractive. The...

8 minutes read.

CSS Gradient

CSS Gradient: The CSS gradient property is applied to show the smooth transition inside two specified colors or more than two specified colors. Need of CSS Gradient The following are a few...

4 minutes read.

CSS Button Style

CSS button style: Using CSS properties, we can easily modify the default BUTTON and enhance its appearances using simple graphic commands. TYPES OF BUTTON STYLE: - Program to change button using CSS ...

35 minutes read.

CSS Box-shadow

CSS Box-shadow This property is referred to include effects as shadow-like around an element’s frame. Syntax box-shadow: h-offset v-offset blur spread color |inset|inherit|none; Property values Following are the various property values which can be used...

3 minutes read.

Internal CSS

What is CSS? CSS stands for Cascading Style Sheet.CSS is used to apply styling the HTML elements.With CSS user can add or change color, font-size and font-family. It also helps user...

4 minutes read.

Cascading Style Sheet

CSS refers to the Cascading Style Sheet. CSS is a form of a programming language. In other words, CSS is a language of the style sheet that is utilised for...

7 minutes read.

CSS Color

CSS Colors: The CSS color property is used for setting the HTML element’s color. The color of the fonts and the color of the background can be set-up by using...

5 minutes read.

What is Bootstrap CSS?

Bootstrap: - Bootstrap is a CSS framework that is free to use and is used for the front-end development of the website in a faster and easier way. Bootstrap was released as...

3 minutes read.

CSS Navigation bar

CSS Navigation bar: A navigation system or navigation bar comes upon GUI that can help many visitors to access the information. A Navigation bar is a UI component on the...

11 minutes read.

CSS Superscript and Subscript

Superscript and Subscript To specify the superscript and the subscript text, HTML provides us two tags that are <sup> and <sub>. The superscript content looks in the shorter font and half...

2 minutes read.

Difference between HTML and CSS

HTML HTML stands for HyperText Markup Language and is used to create web pages and websites and web applications, which means we can create static web pages. Html is a scripting...

3 minutes read.

CSS: nth-selector

CSS nth selector can be used to match an element according to its position regardless of its parent’s type. Here, n can be any number, formula, or a keyword. These selectors...

2 minutes read.

CSS Zoom

CSS Zoom: Zoom property in CSS extents the content. This property controls the content’s level of magnification. Rather than the use of this CSS property, we may also apply the...

3 minutes read.

CSS User Interface

Introduction User Interface can be defined as series of visual elements like screens, buttons, forms that help the user interact with the software application or hardware device. CSS User Interface allows the...

6 minutes read.

Radial-gradient() CSS function

Radial-gradient() CSS function It defines a CSS in-built function, which produces a smooth transition among multiple colors. It is used to set any radial-gradient that is same as a background-image. This...

4 minutes read.

CSS Comments

CSS Comments: Generally, comments in CSS are used to describe our code. Further, it will provide support to many users who are concerned with the code. Somewhat, these are ignored...

2 minutes read.

Css Box Model

Introduction The Box Model property of CSS is used for design and layout of an html page. In CSS, all the elements has a rectangular box around it, you have to...

5 minutes read.

CSS Links

CSS Link is used to create styled link. There are various ways to implement it. Styling Links Link can be styled with CSS properties like color, font-family, background etc. Example: <!DOCTYPE html>   <html>   <head>   <style>   a {       color: red;   }   </style>   </head>   <body>   <p><b><a href="https://www.tutorialandexample.com"    target="_blank">This is a link</a></b></p>   </body>   </html> Try Now There are four...

2 minutes read.

CSS Image Gallery

Image galleries are used to display and store collections of images. Example Let’s discuss an example. CSS was used to create the following image gallery: Code is as follows: <html> <head> <style> div.gallery {   margin: 6px;   border: 1px...

5 minutes read.

CSS Selector

CSS Selector: There are some selectors used in CSS, which allows us to choose the content we wish to style. Various selectors are considered as the separation of the set...

5 minutes read.