CSS Fonts


Why Is Font Choice Important?

The choice of font significantly affects how readers interact with a website. Your brand can develop a strong identity with the help of the correct typeface.

It's crucial to have a font that is simple to read. Your writing is made better by the font. The right colour and text size for the font should be chosen as well.

Fundamental Font Families. There are five standard font families in CSS:

  • Each letter in a serif font has a little stroke around the outside. They convey an air of formality and refinement.
  • Sans-serif typefaces are simple in design (no small strokes attached). They give the area a contemporary, clean appearance.
  • Monospace fonts: in these, every letter has a fixed width. They produce a mechanical appearance.
  • Cursive fonts mimic writing done by hand.
  • Fantasy fonts are ornamental or whimsical typefaces.
  • All of the many font names come from one of the common font families.

The HTML element's font content is set using the CSS font. The following list and brief discussion of some of the many font properties in CSS:

  • CSS font-family Property: The typeface of an element is specified via the font-family property.
  • CSS font-style Property: Any sort of text can have its appearance customized by using the CSS font-style attribute.
  • CSS font-weight Property: The thickness or weight of the font used with HTML text is set using the font-weight property of CSS.
  • CSS font-variant Property: All lowercase letters are changed to uppercase using the font-variant parameter.
  • CSS font-size Property: To control the font size of text in an HTML document, use the font-size property in CSS.
  • CSS font-stretch Property: To make text broader or narrower, use the font-stretch CSS property.
  • CSS font-kerning Property: The use of the Kerning Information that has been saved in the Font is managed by this attribute.

1. font-family:

An HTML element's font type is set using it. As a backup system, it has several font names stored.

Syntax

Example

Preview

2. font-style:

An HTML element's font style can be specified using it. The options are "regular, italic, or oblique."

Syntax

Example

Preview

3. font-weight:

It is used to control the font's boldness. It might have a value that is "regular, bold, lighter, or bolder."

Syntax

Example

Preview

4. font-variant:

To get the small-caps impression, it is utilized. "Normal or small-caps" are two options.

Syntax

Example

Preview

5. font-size:

An HTML element's font size is set using it. There are various ways to set the font size, including "pixels, %, em or we can set values like tiny, large," etc.

Syntax

Example

Preview

FAQs

To use custom fonts in CSS, first, define the @font-face rule with the font file's location and format. Then, use the font-family property to specify the custom font's name, and apply it to the desired elements.

The default values of font properties in CSS can vary based on the browser being used, but generally, the default font size is 16px, the default font family is usually Times New Roman or a similar serif font, the default font weight is normal, the default font style is normal, and the default text color is black. Additionally, the default line height is typically 1.2 and the default letter spacing is usually normal. It's important to note that these defaults can be overridden with CSS.

CSS font-feature-settings is a property that allows you to enable or disable certain OpenType features in fonts. OpenType fonts have various features, such as ligatures, small caps, and alternate characters. By using the font-feature-settings property, you can enable or disable these features in your text. For example, you could enable ligatures in a font to improve the appearance of text, or disable them to make text more legible. The font-feature-settings property can be used with the font-variant property to provide even more control over the appearance of text.