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

Text Decoration


The text-decoration property is a shorthand for specifying the appearance of decorative lines on text. It combines text-decoration-line, text-decoration-color, text-decoration-style, and text-decoration-thickness into a single declaration.


Example 1: Underlining Text

/* This rule targets any element with the class "underline-text" */
.underline-text {
  text-decoration: underline; /* Adds a line underneath the text */
}

Explanation: The text-decoration: underline; declaration adds a horizontal line directly beneath the text. This is commonly used to indicate a hyperlink or to add emphasis.


Example 2: Overlining Text

/* This rule applies to elements with the class "overline-text" */
.overline-text {
  text-decoration: overline; /* Adds a line above the text */
}

Explanation: text-decoration: overline; places a decorative line on top of the text. This is a less common decoration, used for specific design effects.


Example 3: Striking Through Text

/* This CSS rule is for any element with the class "strikethrough-text" */
.strikethrough-text {
  text-decoration: line-through; /* Draws a line through the middle of the text */
}

Explanation: The text-decoration: line-through; value draws a line directly through the center of the text. This is often used to indicate that text has been deleted or is no longer relevant.


Example 4: Combining Decorations with Color and Style

/* This rule targets elements with the class "fancy-decoration" */
.fancy-decoration {
  text-decoration: underline dotted red; /* Underline, dotted style, red color */
}

Explanation: The text-decoration shorthand allows for combining multiple values. In this example, underline dotted red creates a red, dotted line underneath the text, demonstrating how to specify the line's style and color.


Example 5: Wavy Underline

/* This rule is for any element with the class "wavy-underline" */
.wavy-underline {
  text-decoration: underline wavy blue; /* Creates a wavy blue underline */
}

Explanation: By using the wavy keyword, you can create a wavy line for the text decoration. This example applies a blue, wavy underline, which is often used to indicate spelling or grammar errors in text editors.


Example 6: Changing Decoration Thickness

/* This CSS rule targets elements with the class "thick-decoration" */
.thick-decoration {
  text-decoration: underline solid green 3px; /* Green, solid underline that is 3 pixels thick */
}

Explanation: You can control the thickness of the decoration line by adding a length value. Here, 3px sets the thickness of the solid green underline, making it more prominent.


Example 7: Removing Text Decoration

/* This rule applies to anchor tags with the class "no-decoration" */
a.no-decoration {
  text-decoration: none; /* Removes any text decoration */
}

Explanation: The text-decoration: none; declaration is commonly used to remove the default underline from hyperlinks (<a> tags) for stylistic purposes, creating a cleaner look for navigation menus and other links.