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 Transform


The text-transform property in CSS is used to control the capitalization of text. It allows you to change text to all uppercase, all lowercase, or capitalize the first letter of each word, without altering the original HTML content.


Example 1: Uppercase Text

/* This rule targets elements with the class "uppercase-text" */
.uppercase-text {
  text-transform: uppercase; /* Transforms all characters to uppercase */
}

Explanation: The text-transform: uppercase; declaration converts every letter in the targeted text to its uppercase equivalent. This is often used for headings and titles to make them stand out.


Example 2: Lowercase Text

/* This CSS rule applies to any element with the class "lowercase-text" */
.lowercase-text {
  text-transform: lowercase; /* Transforms all characters to lowercase */
}

Explanation: By setting text-transform: lowercase;, all characters in the text are converted to lowercase. This can be useful for creating a specific stylistic tone or for normalizing user input.


Example 3: Capitalizing Words

/* This rule is for elements with the class "capitalize-text" */
.capitalize-text {
  text-transform: capitalize; /* Capitalizes the first letter of each word */
}

Explanation: The text-transform: capitalize; value transforms the first letter of each word to uppercase. The remaining letters of the word are unaffected, making this ideal for titles and headlines.


Example 4: No Transformation

/* This rule targets elements with the class "no-transform" */
.no-transform {
  text-transform: none; /* Prevents any capitalization changes */
}

Explanation: text-transform: none; ensures that the text renders exactly as it is in the HTML source code, without any case transformations. This is the default behavior and is useful for overriding inherited text-transform styles.


Example 5: Full-Width Transformation

/* This CSS rule applies to elements with the class "full-width-text" */
.full-width-text {
  text-transform: full-width; /* Transforms characters to their full-width variants */
}

Explanation: The text-transform: full-width; value transforms all characters into their corresponding full-width form. This is primarily used for aligning text in East Asian scripts with a fixed-width grid.


Example 6: Overriding an Inherited Transform

/* Parent element has uppercase transform */
.parent-container {
  text-transform: uppercase;
}

/* Child element overrides the parent's transform */
.child-element {
  text-transform: none; /* Resets the transform for this specific element */
}

Explanation: In this scenario, a parent element is set to have uppercase text. However, the child element with the class .child-element has text-transform: none;, which prevents it from inheriting the parent's transformation, allowing it to display its original case.


Example 7: Capitalizing a Button's Text

/* This rule styles a button element */
.action-button {
  text-transform: uppercase; /* Makes the button text uppercase */
  font-weight: bold; /* Makes the text bold for emphasis */
  padding: 10px 20px; /* Adds padding for a larger click area */
}

Explanation: Here, text-transform: uppercase; is applied to a button to make its call-to-action text more prominent and visually distinct. This is a common design pattern for buttons to draw user attention.