CSS font-variant property


The font-variant Property in CSS

The font-variant property in CSS is used to control the use of different types of font features, primarily focusing on typographic variations. It enables the application of specific font features that are part of a font's advanced typography settings. This property is useful for enhancing text presentation with special typographic effects and features.

Values of font-variant

  1. normal

    • Description: The default value. It uses the standard font without any special typographic features applied.
    • Example:
      .normal-text { font-variant: normal; }
  2. small-caps

    • Description: Renders text in small capital letters. Small caps are uppercase letters but at a smaller size than standard capital letters.
    • Example:
      .small-caps-text { font-variant: small-caps; }
  3. all-small-caps

    • Description: Renders all text in small capital letters, even those that are typically lowercase.
    • Example:
      .all-small-caps-text { font-variant: all-small-caps; }
  4. caps

    • Description: A shorthand for font-variant-caps and applies the small-caps style to text.
    • Example:
      .caps-text { font-variant: caps; }
  5. lining-nums

    • Description: Uses lining figures (numbers that align with the height of the capital letters) rather than old-style figures (numbers that have varying heights and align with the baseline).
    • Example:
      .lining-nums-text { font-variant: lining-nums; }
  6. oldstyle-nums

    • Description: Uses old-style figures for numbers, which have varying heights and align with the baseline.
    • Example:
      .oldstyle-nums-text { font-variant: oldstyle-nums; }
  7. slashed-zero

    • Description: Renders the digit zero with a slash through it to distinguish it from the letter "O".
    • Example:
      .slashed-zero-text { font-variant: slashed-zero; }
  8. sub and super

    • Description: These values are used for setting subscript and superscript text, respectively.
    • Example:
      .sub-text { font-variant: sub; /* Subscript */ } .super-text { font-variant: super; /* Superscript */ }

Examples

  1. Small Caps

    .small-caps { font-variant: small-caps; /* Text is rendered in small caps */ }
  2. Lining Figures

    .lining-nums { font-variant: lining-nums; /* Uses lining figures for numbers */ }
  3. Oldstyle Figures

    .oldstyle-nums { font-variant: oldstyle-nums; /* Uses old-style figures for numbers */ }
  4. Slashed Zero

    .slashed-zero { font-variant: slashed-zero; /* Uses slashed zero */ }

Explanation

  • normal: No special typographic features are applied; the text appears in its default style.
  • small-caps: Renders text in smaller capital letters, which is often used for emphasis or stylistic purposes.
  • all-small-caps: Converts all text to small capital letters, including lowercase letters.
  • lining-nums: Ensures that numbers align with capital letters, which is often preferred in modern typography for consistency.
  • oldstyle-nums: Provides a traditional look with numbers that have varying heights, often used in classic typography.
  • slashed-zero: Distinguishes the number zero from the letter "O" for clarity in numerical contexts.
  • sub and super: Used to render text as subscript or superscript, which is useful in mathematical or scientific contexts.

Use Cases

  • Typographic Design: Enhance the visual appearance of text with typographic features like small caps or lining figures.
  • Readability: Improve the distinction between similar characters or numerals, such as using slashed zero to avoid confusion.
  • Stylistic Choices: Apply specific typographic effects to achieve desired design aesthetics.