CSS

CSS Overview Selectors Declarations Rule Sets Comments Reset/Normalize Origin Importance Order Specificity Inheritance Cascade Layers Inline Styles Internal Styles External Styles @import Absolute Units Relative Units Dynamic Viewport Angle Units Time Units Frequency Units: Resolution Units Keywords Color Formats Color Functions & Spaces Background Color Background Image Background Repeat Background Position Background Size Background Attachment Background Shorthand Multiple Backgrounds Linear Gradients Radial Gradients Conic Gradients Font Family Font Size Font Weight Font Style Line Height Text Align Text Decoration Text Transform Letter Spacing Word Spacing Text Shadow Text Wrap Variable Fonts Content Box Padding Box Border Box Margin Box Box Sizing Property Margin Padding Border Outline Box Shadow Block Display Inline Display Inline Block Display Static Position Relative Position Absolute Position Fixed Position Sticky Position Top Element Position Right Element Position Bottom Element Position Left Element Position Z Index Flexbox Box Layout Display Flex Flex Direction Flex Wrap Justify Content Align Items Align Content Gap, Row Gap & Column Gap Flex Grow Flex Shrink Flex Basis Flex Shorthand Order Property Align Self Practical Applications CSS Grid Layout Grid Display Grid Template Columns Grid Template Rows Grid Template Areas Justify Items Grid Auto Columns Justify Self Nested Grids Responsive Web Design Min Width Max Width Orientation Logical Operators Pointer Hover Prefers Color Scheme Fluid Images Flexible Typography Viewport Width Advanced CSS Features Defining variables Using variables Scope & Inheritance of CSS Variables Property Value Fallback Practical Applications :Hover :Active :Focus :Focus Visible :Visited :Link :First Child :Last Child :Nth Child :Nth of Type :Empty :Checked :Disabled :Enabled :Valid :Invalid :Required :Has :Not :Is :Where ::Before Pseudo Element ::After Pseudo Element ::First Letter ::First Line ::Selection ::Marker CSS 2D Transformations CSS 3D Transformations Transform Origin Transform Style Backface Visibility Transition Property Transition Duration Transition Timing Function Transition Delay Transition Shorthand Ease Timing Function Linear Timing Function Ease In Timing Function Ease Out Timing Function Ease In Out Timing Function Cubic Bezier Function Animations (@keyframes) Defining @keyframes Animation Name CSS Animation Duration Animation Timing Function CSS Animation Delay CSS Animation Iteration Count Animations Direction CSS Animation Fill Mode CSS Animation Play State CSS Filter Blur CSS Filter Brightness CSS Filter Contrast() CSS Drop Shadow CSS Grayscale CSS Hue Rotate CSS Invert CSS Opacity CSS Saturate CSS Sepia Mix Blend Mode Background Blend Mode Object Fit & Object Position Scroll Snap Type Scroll Snap Align Scroll Padding Scroll Margin Scroll Triggered Animations JS Variables

Font Style


The font-style property in CSS is primarily used to specify an italic or oblique face for a font. While italic is a specially designed italic version of the font, oblique is a slanted version of the normal font. If an italic version of a font is not available, browsers will typically substitute an oblique version.


Example 1: Using the italic Keyword

/* This rule targets all emphasis elements. */
em {
  /* It applies an italic style to the text. */
  font-style: italic;
}

Explanation

This code sets the font-style to italic, which is the most common way to italicize text for emphasis.


Example 2: Using the normal Keyword

/* This rule targets an italic element within a heading. */
h1 i {
  /* It removes the italic styling, making the text appear normal. */
  font-style: normal;
}

Explanation

The normal keyword is used to reset the font style to its default, non-italic, non-oblique appearance.


Example 3: Using the oblique Keyword

/* This rule applies to elements with the class "slanted-text". */
.slanted-text {
  /* It applies an oblique (slanted) style to the text. */
  font-style: oblique;
}

Explanation

The oblique value will display a slanted version of the regular font. This is a good fallback if a true italic font is not available.


Example 4: Specifying an Angle for oblique

/* This rule targets elements with the class "custom-slant". */
.custom-slant {
  /* It applies an oblique style with a specific 15-degree slant. */
  font-style: oblique 15deg;
}

Explanation

You can specify an angle for the oblique style, giving you more precise control over the slant of the text.


Example 5: Combining with font-weight

/* This rule targets blockquote elements. */
blockquote {
  /* It creates a bold and italic style for the text. */
  font-style: italic;
  font-weight: bold;
}

Explanation

font-style can be combined with other font properties like font-weight to create more complex text styling.


Example 6: Styling an Entire Section

/* This rule applies to the footer of the page. */
footer {
  /* It sets the entire footer text to be italic. */
  font-style: italic;
}

Explanation

This example demonstrates how you can apply a font-style to a larger container element, affecting all the text within it.


Example 7: Using oblique with a Negative Angle

/* This rule targets elements with the class "reverse-slant". */
.reverse-slant {
  /* It applies an oblique style with a negative angle, slanting the text to the left. */
  font-style: oblique -10deg;
}

Explanation

A negative angle with the oblique value will cause the text to slant to the left instead of the more traditional right.