Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS font-variant Property

Posted in CSS Tutorial
Updated on Aug 04, 2024
By Mari Selvan
👁️ 10 - Views
⏳ 4 mins
💬 1 Comment
CSS font-variant Property

Photo Credit to CodeToFun

🙋 Introduction

The font-variant property in CSS is used to control the usage of alternate glyphs within a font. It allows you to specify whether certain characters, such as small capitals or old-style figures, should be used.

This property can enhance the typographic presentation of your text, adding a unique touch to your web content.

💡 Syntax

The syntax for the font-variant property is straightforward. It can be applied to any text element.

Syntax
Copied
Copy To Clipboard
element {
  font-variant: value;
}

🎛️ Default Value

The default value of the font-variant property is normal, which means no special variant glyphs are used and the text is displayed in its normal form.

🏠 Property Values

ValueDescription
normalThe default value, which specifies a normal font face without any variants.
small-capsTransforms lowercase letters into smaller uppercase letters.
all-small-capsChanges all characters to small caps, including uppercase characters.
petite-capsTransforms lowercase letters into petite capitals, a smaller version of small-caps.
all-petite-capsChanges all characters to petite caps, including uppercase characters.
unicaseA mix of uppercase and lowercase letters for stylistic purposes.
titling-capsUses a titling font, which is designed for use in titles.

📄 Example

In this example, we'll apply the font-variant property to transform text into small capitals.

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS font-variant Example</title>
  <style>
    .small-caps {
      font-variant: small-caps;
    }
  </style>
</head>
<body>
  <h1>Font Variant Example</h1>
  <p class="small-caps">This text is displayed in small capitals.</p>
</body>
</html>

🖥️ Browser Compatibility

The font-variant property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. However, it is always a good practice to test your website across different browsers to ensure compatibility.

🎉 Conclusion

The font-variant property is a useful tool for web developers looking to enhance the typographic presentation of their text.

By using this property, you can add stylistic variations to your fonts, making your web content more visually appealing and engaging. Experiment with different values to see how this property can improve the look and feel of your text.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy