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 Weight


The font-weight property is used to set the thickness or boldness of a font. It can be defined using keywords like normal and bold, or with numeric values ranging from 100 to 900. Not all fonts have all nine weight values available.


Example 1: Using the bold Keyword

/* This rule targets elements with the class "important". */
.important {
  /* It makes the text bold. */
  font-weight: bold;
}

Explanation

The bold keyword is a common way to make text stand out. It is typically equivalent to a numeric value of 700.


Example 2: Using the normal Keyword

/* This rule targets all bold elements within a specific section. */
.some-section b {
  /* It resets the font weight to normal. */
  font-weight: normal;
}

Explanation

The normal keyword sets the font weight to its default, non-bold state. This is equivalent to a numeric value of 400.


Example 3: Using a Numeric Value

/* This rule applies to all h3 elements. */
h3 {
  /* It sets a specific numeric font weight. */
  /* A value of 600 is considered semi-bold. */
  font-weight: 600;
}

Explanation

Numeric values provide more granular control over the font's thickness, assuming the font family supports different weights.


Example 4: Using a Lighter Font Weight

/* This rule targets elements with the class "subtle-text". */
.subtle-text {
  /* It sets a lighter font weight. */
  /* A value of 300 is a common light weight. */
  font-weight: 300;
}

Explanation

Lighter font weights, like 300, can be used to de-emphasize text or create a more delicate and modern look.


Example 5: Using the bolder Keyword

/* This rule targets a nested strong element. */
p strong {
  /* It makes the text bolder than its parent element. */
  font-weight: bolder;
}

Explanation

The bolder keyword makes the text one step bolder than the parent element's font weight.


Example 6: Using the lighter Keyword

/* This rule applies to a span within a heading. */
h2 span {
  /* It makes the text lighter than its parent element. */
  font-weight: lighter;
}

Explanation

Similar to bolder, the lighter keyword makes the text one step lighter than the parent element's font weight.


Example 7: Specifying a Range for Variable Fonts

/* This rule targets a paragraph and assumes a variable font is being used. */
p {
  /* It sets a specific weight within the font's available range. */
  font-weight: 550;
}

Explanation

With variable fonts, you are not limited to increments of 100 and can specify any numeric value within the font's supported range.