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

:Disabled


The :disabled pseudo-class targets form elements that have the disabled attribute set, meaning they cannot be focused, clicked, or otherwise interacted with. This is useful for visually indicating to the user that a form control is not currently available.


Example 1: Styling a Disabled Button

/* This CSS rule targets a button element when it is disabled. */
button:disabled {
  /* The background-color property changes the button's color to a light gray. */
  background-color: #cccccc;
  /* The cursor property changes the mouse pointer to a "not-allowed" symbol. */
  cursor: not-allowed;
}

Explanation

This code changes the appearance of a button when it is disabled to provide a clear visual cue that it cannot be clicked. The background becomes gray, and the cursor changes to indicate it's not clickable.


Example 2: Fading Out Disabled Text Inputs

/* This CSS rule targets a text input when it is disabled. */
input[type="text"]:disabled {
  /* The opacity property makes the input partially transparent. */
  opacity: 0.5;
  /* The background-color is changed to a light gray. */
  background-color: #f5f5f5;
}

Explanation

This CSS makes disabled text inputs appear faded and with a different background color. This visually separates them from active input fields, improving form clarity.


Example 3: Hiding Labels of Disabled Fields

/* This CSS rule targets the label of a disabled input. */
input:disabled + label {
  /* The display property is set to none, hiding the label. */
  display: none;
}

Explanation

In some cases, you might want to hide the label of a disabled form field. This code uses the adjacent sibling combinator (+) to select and hide the label that immediately follows a :disabled input.


Example 4: Styling a Disabled Fieldset

/* This CSS rule targets a fieldset element when it is disabled. */
fieldset:disabled {
  /* The border property is changed to a dashed gray line. */
  border: 1px dashed #ccc;
}

/* This rule styles the legend of a disabled fieldset. */
fieldset:disabled legend {
  color: #ccc;
}

Explanation

When a <fieldset> is disabled, all its descendant form controls also become disabled. This CSS provides a visual cue by changing the border of the fieldset and graying out the text of its <legend>.


Example 5: Cross-through Text on Disabled Options

/* This CSS rule targets an option within a select element when it is disabled. */
option:disabled {
  /* The text-decoration property adds a line-through the text. */
  text-decoration: line-through;
  color: #999;
}

Explanation

This code styles disabled <option> elements within a dropdown. The text-decoration: line-through makes it clear that the option is unavailable for selection.