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

Letter Spacing


The letter-spacing property in CSS controls the amount of horizontal space between characters in a text. It can be used to increase or decrease the spacing to improve readability or for stylistic effect.


Example 1: Increasing Letter Spacing

/* This rule targets elements with the class "loose-spacing" */
.loose-spacing {
  letter-spacing: 2px; /* Adds 2 pixels of space between each character */
}

Explanation: Setting letter-spacing to a positive value like 2px increases the space between letters, creating a more open and airy feel. This is often used in headlines and logos for a stylized appearance.


Example 2: Decreasing Letter Spacing

/* This CSS rule applies to elements with the class "tight-spacing" */
.tight-spacing {
  letter-spacing: -1px; /* Removes 1 pixel of space between each character */
}

Explanation: A negative letter-spacing value, such as -1px, reduces the space between characters, making the text appear more condensed. This technique, also known as kerning, can be used to improve the visual balance of certain letter combinations.


Example 3: Normal Letter Spacing

/* This rule is for elements with the class "normal-spacing" */
.normal-spacing {
  letter-spacing: normal; /* Resets the letter spacing to the font's default */
}

Explanation: The letter-spacing: normal; declaration resets the spacing between characters to the default value defined by the current font. This is useful for overriding any inherited letter-spacing styles.


Example 4: Using em Units for Spacing

/* This rule targets elements with the class "em-spacing" */
.em-spacing {
  letter-spacing: 0.1em; /* Sets spacing relative to the font size */
}

Explanation: Using relative units like em for letter-spacing allows the spacing to scale proportionally with the font-size. A value of 0.1em adds space that is 10% of the current font size between each letter.


Example 5: Animating Letter Spacing on Hover

/* This CSS rule applies to elements with the class "hover-spacing" */
.hover-spacing {
  letter-spacing: 1px; /* Initial letter spacing */
  transition: letter-spacing 0.3s ease; /* Smooth transition for the spacing change */
}

.hover-spacing:hover {
  letter-spacing: 3px; /* Increases spacing when the mouse is over the element */
}

Explanation: This example demonstrates a common interactive effect where the letter-spacing increases when a user hovers over the text. The transition property ensures a smooth animation between the initial and hovered states.


Example 6: Applying Letter Spacing to Uppercase Text

/* This rule is for headings that are uppercase and have increased spacing */
h1.spaced-title {
  text-transform: uppercase; /* Makes the heading uppercase */
  letter-spacing: 4px; /* Adds significant space between letters for a dramatic effect */
}

Explanation: Combining text-transform: uppercase; with a generous letter-spacing is a popular technique for creating stylish, modern headings. The increased spacing improves the readability of the all-caps text.


Example 7: Fine-Tuning Spacing with Decimal Values

/* This rule targets elements with the class "fine-tuned-spacing" */
.fine-tuned-spacing {
  letter-spacing: 0.5px; /* Adds a half-pixel of space between characters */
}

Explanation: For precise typographic control, letter-spacing can be set using decimal values. A subtle adjustment like 0.5px can make a noticeable difference in the overall texture and readability of a block of text.