The Wayback Machine - https://web.archive.org/web/20240930222706/https://www.geeksforgeeks.org/css-font-style-property/
Open In App

CSS font-style Property

Last Updated : 26 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The CSS font-style property is used to style text in a normal, italic, or oblique face from its font family. This property helps to assign importance and decorate specific text, enhancing the overall user experience. The font-style property is an essential tool in CSS for designing and styling text effectively.

Syntax:  

font-style: normal|italic|oblique|initial|inherit;

Property values: 

  • normal: This is the default value for the font-style property, displaying normal font text.
  • italic: Displays the text in italics.
  • oblique: Specifies an angle for the slant of the text, displayed as oblique in the browser.
  • initial: Sets the font to its default value.
  • inherit: Inherits the current property value from its parent element.

We will discuss all the font-style properties through the examples. Let’s begin with the normal font-style property.

1. font-style: normal:

The browser will display normal font text it is the default value.

Syntax: 

font-style: normal;

Example: This example illustrates the font-style whose value is set to normal.

HTML
<!DOCTYPE html>
<html>
<head>
    <title> CSS | font-style Property </title>
    <style>
    p.a {
        font-style: normal;
    }
    </style>
</head>

<body>
    <h1>GeeksforGeeks</h1>
    <h3>Normal font-style Property</h3>
    <p class="a">GeeksforGeeks</p>

</body>
</html>

Output:

2. font-style: italic:

This is used for making font in italic.

Syntax:

font-style: italic;

Example: This example illustrates the font-style whose value is set to italic.

HTML
<!DOCTYPE html>
<html>
<head>
    <title> CSS | font-style Property </title>
    <style>
    p.a {
        font-style: italic;
    }
    </style>
</head>

<body>
    <h1>GeeksforGeeks</h1>
    <h3>Italic font-style Property</h3>
    <p class="a">GeeksforGeeks</p>

</body>
</html>

Output: 

3. font-style:oblique:

The browser displays an oblique font style.

Syntax: 

font-style: oblique;

Example: This example illustrates the font-style whose value is set to oblique.

HTML
<!DOCTYPE html>
<html>
<head>
    <title> CSS | font-style Property </title>
    <style>
    p.a {
        font-style: oblique;
    }
    </style>
</head>

<body>
    <h1>GeeksforGeeks</h1>
    <h3>Oblique font-style Property</h3>
    <p class="a">GeeksforGeeks</p>

</body>
</html>

Output:

4. font-style:initial:

The browser displays an initial font style which is the default.

Syntax: 

font-style: initial;

Example: This example illustrates the font-style whose value is set to initial.

HTML
<!DOCTYPE html>
<html>
<head>
    <title> CSS | font-style Property </title>
    <style>
    p.a {
        font-style: initial;
    }
    </style>
</head>

<body>
    <h1>GeeksforGeeks</h1>
    <h3>Initial font-style Property</h3>
    <p class="a">GeeksforGeeks</p>

</body>
</html>

Output:

5. font-style:Inherit:

This inherits property from its parent element.

Example: In this example, we have set the value of color as inherit that will be inheriting the color property from its parent element.

HTML
<!DOCTYPE html>
<html>
<head>
    <title> CSS | font-style Property </title>
    <style>
    span {
        color: blue;
        font-size: 70px;
    }
    
    .extra span {
        color: inherit;
    }
    </style>
</head>

<body>
    <div> 
        <span>GeeksforGeeks</span> 
    </div>
    <div class="extra" 
         style="color:green"> 
      <span>GeeksforGeeks</span> 
    </div>
    <div style="color:red"> 
        <span>GeeksforGeeks</span> 
    </div>
</body>
</html>

Output:

Conclusion

The CSS font-style property is a fundamental aspect of web design, allowing developers to control the appearance of text on their webpages. Whether you need to emphasize text with italic or oblique styles, or simply maintain a normal font appearance, understanding and utilizing the font-style property is crucial. By mastering this property, you can enhance the visual appeal and readability of your web content. For more information and examples, refer to our comprehensive CSS tutorial and explore additional CSS properties to elevate your web design skills.

Supported Browsers: The browser supported by font-style Property are listed below: 

  • Google Chrome 1.0
  • Microsoft Edge 12.0
  • Firefox 1.0
  • Opera 7.0
  • Safari 1.0

CSS font-style Property – FAQs

What does the font-style property do in CSS?

The font-style property in CSS specifies whether the text should be displayed in a normal, italic, or oblique style. It’s commonly used to apply emphasis or differentiate parts of text.

What values can be used with font-style?

The font-style property accepts three values: normal, italic, and oblique. “Normal” shows regular text, “italic” displays slanted text typically based on the italic version of the font, and “oblique” slants the text, usually without a true italic typeface.

What is the difference between italic and oblique?

“Italic” uses a font’s true italic style, if available, while “oblique” simply slants the text without using a specifically designed italic font. Oblique is more of an artificially slanted version of the font.

Can I use font-style to style only part of the text within an element?

No, font-style applies to the entire element. To style only part of the text, you would need to wrap that part in a separate element, such as a span, and apply font-style to that element.

What is the default value of font-style?

The default value for font-style is normal, meaning the text is displayed without any slant or italicization.



Previous Article
Next Article

Similar Reads

HTML | DOM Style font Property
The HTML DOM Style's font property is used to change the element's font properties. It can be used to change the font style, weight, size, and family. Syntax: To set the font style :node.style.font = "font-properties font-size font-family;"To get the current font style:node.style.font; Return Values: It returns a string value, which represents diff
2 min read
Foundation CSS Global Style Font Sizing
Foundation CSS offers a global font scaling strategy that enables web developers to specify uniform font sizes across their websites. It is a front-end framework that offers a library of pre-built components, styles, and templates. Foundation CSS's global style font scaling method allows developers to specify font sizes for all components, includin
5 min read
How to change the Font Style in CSS ?
Font style in CSS is important for making web page text more presentable. The font-style property determines how the text within an element is displayed, defining whether the text should be normal, italic, or oblique. Syntaxelement { font-family: family-name | generic-family; font-style: normal | italic | oblique; font-variant: normal | small-caps;
4 min read
Tailwind CSS Font Style
This class accepts lots of value in tailwind CSS in which all the properties are covered as in class form. It is the alternative to the CSS font-style property. If we want to give design to any type of text then we can make the use of Tailwind CSS font style class. It helps to make a better user experience. Font Style classes: italicnon-italicitali
2 min read
How to add multiple font files for the same font ?
@font-face In CSS, it is a rule that specifies a custom font. This allows us to expand our scope beyond the web-safe fonts. In this rule, @font-face must be first defined and then webpage elements can be made to refer to it as required. Objective: To define multiple font files under the same font name. Framing this in a more understandable way, wha
2 min read
How to remove CSS style of <style> tag using JavaScript/jQuery ?
Given an HTML document containing inline and internal CSS and the task is to remove the style of <style> tag. The internal or embedded CSS is used within the head section of the HTML document. It is enclosed within <style> tag. Approach: The jQuery remove() and empty() methods are used to remove the CSS style of <style> element. E
2 min read
How to change the font style of a text canvas using Fabric.js ?
In this article, we are going to see how to change the font style of a text canvas using FabricJS. The canvas means text written is movable and can be stretched according to the requirement. Further, the text itself cannot be edited like a textbox.Approach: To make it possible we are going to use a JavaScript library called FabricJS. After importin
2 min read
How to change font style using drop-down list in JavaScript ?
To change or set a font style for certain text, the fontFamily CSS property needs to be changed. The fontFamily property sets or returns a list of font-family names for text in an element. Syntax: object.style.fontFamily = "font" To change the font style by option dropdown: The font values can be passed in option tags using option value. Syntax:
2 min read
SVG font-style Attribute
The font-style attribute is used to specify whether the text is to be rendered using a normal, italic, or oblique face style. Syntax: font-style="style" Attribute Values: The attribute can have the following values: normal: This specifies that the text should be displayed in the normal form.italic: This specifies that the text should be displayed i
1 min read
How to set text color & font style in HTML ?
In this article, we will learn how to set text color & font style in HTML. The <style> tag in HTML helps us to set the text color & font style in HTML. This modification includes changing font size, font family, font color, etc. Not only the text but also we can change the style of a body or part of a page. We can add style in differe
2 min read
How to change font style on element using Bootstrap 5?
Bootstrap enables changing font styles by applying predefined classes like .fw-bold for bold, .fst-italic for italic, etc., directly to HTML elements. This ensures consistent and responsive typography across web applications without needing custom CSS. There are a few Bootstrap Built-in Classes for adding the styling to the font, which are describe
2 min read
How to set whether the style of the font is normal, italic or oblique with JavaScript ?
JavaScript document.getElementBy() methods can help us to check the font style of an element. It's the easiest way to know any CSS property values applied to a specific element. The default font-style value is 'normal'. We can easily check the value of the font-style property by selecting the particular element using the getElementBy method and che
4 min read
CSS font-stretch Property
The font-stretch property in CSS is used to set the text wider or narrower. This property is not working any font. Its only work when font family has a width-variant face. Syntax: font-stretch: normal|ultra-condensed|extra-condensed|condensed| semi-condensed|semi-expanded|expanded|extra-expanded|ultra-expanded; Default Value: normal Property Values
2 min read
Which property is used as shorthand to specify a number of other font properties in CSS ?
In this article, we are going to discuss a property that is used as shorthand to specify different font properties. The font property is a shorthand property for various font-related properties. Shortening the code in Cascade Style Sheet (CSS) helps to specify all individual related properties into a single property. The font property is used as sh
2 min read
CSS | font-display property
While using web fonts, the text will be invisible until either web font is loaded or three seconds are passed, at which point the fallback font is used. Font-display allows customizing how web fonts are displayed when the page is being rendered. It is applied using @font-face rule which defines custom fonts in a style sheet. Syntax: @font-face { fo
2 min read
CSS font-variant-numeric Property
The font-variant-numeric property of CSS is used to control the usage of alternate glyphs. This is done in terms of units or markers such as numbers or fractions. in other words, the font-variant-numeric property controls the display of numeric characters in a font. It allows you to specify the stylistic variations for numeric digits, such as linin
3 min read
CSS font-variant-position Property
The font-variant-position of CSS is used to alter the position of the font as a superscript, subscript, or normal font. These are positioned relative to the baseline of the font, which remains unchanged. Syntax: font-variant-position: normal | sub | super Property values: Normal: Normal deactivates superscript and subscript glyphs. If not present a
2 min read
CSS font-synthesis Property
The font-synthesis property controls the synthesis of the missing type style such as bold, italic, or underline by the browser. Different font languages like Chinese and Japanese do not include these font variants so synthesizing them may hinder the legibility of the text so the default browser synthesis of the font must be turned off. Syntax: font
2 min read
CSS font-variant-caps Property
The font-variant-caps property changes the position of characters vertically without shifting the baseline and displays them as superscript or subscript. This property selects the most appropriate glyphs if the given font has some capital letter glyphs of different sizes. Syntax: font-variant-caps: keyword_values Or font-variant-caps: Global_values
2 min read
CSS font-variant-ligatures Property
The CSS font-variant-ligatures property is used for controlling ligatures on a text's font. A ligature is a special character that combines two or more characters into one. Ligatures are commonly used to give certain style or look to the text. Syntax: font-variant-ligatures: Keyword_values Or font-variant-ligatures: Global_values Property values: T
1 min read
CSS font-variant-alternates Property
The font-variant-alternates property is one of the CSS3 properties that is generally used for enabling various font related features that can improve the appearance of the text on the page. The font-variant-alternates property is used to specifically select alternate glyphs. For any given character, a variety of alternate glyphs can be provided by
1 min read
How to set font-size-adjust property in CSS ?
The purpose of this article is to set the font-size-adjust property using CSS. Approach: The font-size-adjust property sets the size of lower-case letters relative to the current font size of the upper-case letters. The size difference between the uppercase letters and the lowercase letters is known as the Aspect Value. In case of unavailability of
2 min read
How to use font-feature-settings property in CSS ?
In this article, we learn how to use the font-feature-settings property in CSS, If you want to control the advanced typographic features in open-type fonts then the font-feature-settings property is very useful for developers. One of the properties added to CSS3 is the font-feature-settings property, which enables a variety of font-related features
2 min read
How to use font-optical-sizing property in CSS ?
Whatever web applications or websites we make nowadays, we make sure that it is compatible with all screen sizes. So CSS comes with the font-optical-sizing property which sets whether the text being rendered is optimized for different screen sizes or not. It allows the browser to adjust the outline of font glyph to make them more eligible at differ
2 min read
How to use font-variant-settings property in CSS ?
The font-variant-settings property allow users to get good low-level control over the fonts with variable characteristics. Users may specify the font letter axis name of the character whose value is to be varied. There are two forms to specify this property, one of which is normal, and the second is string number. When the normal property is applie
2 min read
Explain the use of the font Property in CSS ?
The font property in CSS is a shorthand property that allows you to set various font-related properties for text content. It simplifies the process of specifying multiple font properties in a single declaration, providing a concise way to style text. Syntax:/* Example of using the font property */.element { font: [font-style] [font-variant] [font-w
1 min read
CSS font-size Property
The font-size property specifies the size of the font. It can be set using different units, allowing for flexible and responsive designs. It plays a crucial role in ensuring readability, enhancing user experience, and maintaining the overall aesthetics of a website. In this article, we'll learn the various aspects of the font-size property, explori
3 min read
CSS font-family Property
The CSS font-family property specifies the font for an element. It can list multiple fonts as fallbacks. If the browser doesn't support the first font, it tries the next. It includes specific font names like "Arial" and generic families like "serif" or "sans-serif". Types of Font Familyfamily-name: Specific names of font families, such as "Times",
4 min read
CSS font-size-adjust Property
The font-size-adjust property in CSS is used to adjust the font size based on the height of lowercase rather than capital letters and gives better control of the font size. It is very useful when the text has given multiple styles and adjusted the font while changing between those styles. Syntax: font-size-adjust: number|none|initial|inherit;Defaul
2 min read
CSS font-kerning Property
This property is used to control the usage of the Kerning Information that has been stored in the Font. Kerning defines how letters are spaced. This property will have no visible effect on those fonts that do not have kerning information. Syntax: font-kerning: auto|normal|none;Default Value: auto Property: auto: It is the default value. The Browser
2 min read