Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS font Property

Posted in CSS Tutorial
Updated on Oct 02, 2024
By Mari Selvan
👁️ 19 - Views
⏳ 4 mins
💬 1 Comment
CSS font Property

Photo Credit to CodeToFun

🙋 Introduction

The font property in CSS is a shorthand property for setting various individual font-related properties in one declaration.

These properties include font-style, font-variant, font-weight, font-size, line-height, and font-family.

By using the font property, you can quickly apply multiple font settings to an element, ensuring a consistent and cohesive typographic style across your website.

💡 Syntax

The syntax for the font property can vary depending on which values are specified. The general form includes several optional components, followed by mandatory font-size and font-family values.

Syntax
Copied
Copy To Clipboard
element {
  font: [font-style] [font-variant] [font-weight] [font-size]/[line-height] [font-family];
}

🎛️ Default Value

The default value of the font property depends on the browser and operating system settings. Typically, it defaults to the browser's default font style, weight, size, and family.

🏠 Property Values

ValueDescription
font-styleDefines the style of the font. Possible values are normal, italic, and oblique.
font-variantControls the use of small-caps. Possible values are normal and small-caps.
font-weightSpecifies the weight of the font. Values can range from normal, bold, to numeric values like 100 to 900.
font-sizeSets the size of the font. Can be specified in various units like px, em, rem, %, etc.
line-heightSets the height of the line box. Can be a number, length, or percentage.
font-familySpecifies the font family for the text. This can include generic family names like serif, sans-serif, and specific font names.

📄 Example

In this example, we will use the font property to set various font characteristics for a paragraph element.

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 Property Example</title>
  <style>
    p {
      font: italic small-caps bold 16px/1.5 Arial, sans-serif;
    }
  </style>
</head>
<body>
  <h1>Font Property Example</h1>
  <p>
    This paragraph uses the font property to apply multiple font settings in one declaration.
  </p>
</body>
</html>

🖥️ Browser Compatibility

The font property is supported in all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. It's a versatile property that works well across different platforms, making it a reliable choice for styling text.

🎉 Conclusion

The font property in CSS is an efficient way to manage multiple font-related styles in a single declaration.

By understanding and using this property, you can easily control the appearance of text on your web pages, ensuring that it aligns with your overall design aesthetic. Experiment with different combinations of font properties to achieve the desired look and feel for your site's typography.

👨‍💻 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