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

::Marker


The ::marker pseudo-element in CSS allows for the styling of the marker box of a list item, which typically contains a bullet or a number. This provides direct control over the appearance of list markers in both ordered and unordered lists.


Example 1: Basic ::marker Styling

/* Styling the markers of an unordered list */
ul li::marker {
  color: #ff5733; /* Sets the marker color to a shade of orange */
  font-size: 1.2em; /* Makes the marker slightly larger than the list item text */
}

Explanation

This CSS targets the markers of list items within an unordered list (<ul>). It changes their color to orange and increases their size, making the bullet points more prominent.


Example 2: Changing the ::marker Content

/* Custom marker content for an unordered list */
ul li::marker {
  content: '→ '; /* Replaces the default bullet with a right arrow */
  color: #c70039; /* Sets the arrow color to a deep red */
}

Explanation

This example uses the content property to replace the default bullet point of an unordered list with a custom arrow symbol. This is a powerful way to customize the look and feel of your lists.


Example 3: Styling ::marker in an Ordered List

/* Styling the markers of an ordered list */
ol li::marker {
  font-weight: bold; /* Makes the numbers of the list bold */
  color: #333; /* Sets the number color to a dark gray */
}

Explanation

This code targets the numbered markers in an ordered list (<ol>). It makes the numbers bold and changes their color, providing a simple yet effective way to style ordered lists.


Example 4: Using Emojis as ::marker Content

/* Using an emoji as the marker for a list */
ul li::marker {
  content: '✅ '; /* Sets a checkmark emoji as the marker */
}

Explanation

This fun example shows how you can use emojis as list markers. The content property is set to a checkmark emoji, which will appear before each list item.


Example 5: Animating the ::marker

/* Adding a simple animation to the markers */
@keyframes color-change {
  from { color: #ff5733; }
  to { color: #c70039; }
}

li::marker {
  animation: color-change 2s infinite alternate; /* Applies a color changing animation */
}

Explanation

This CSS snippet demonstrates how to apply an animation to list markers. The color of the marker will transition between two colors, creating a dynamic and eye-catching effect.


Example 6: Different ::marker for Specific List Items

/* Styling a marker for a specific list item with a class */
.important-item::marker {
  content: '★ '; /* A star marker for important items */
  color: #ffc300; /* A gold color for the star */
}

Explanation

This example shows how to style the marker of a specific list item by targeting it with a class. This is useful for highlighting certain items within a list, such as a "featured" or "important" item.


Example 7: Combining ::marker with Counters

/* Custom numbered markers using a counter */
ol {
  list-style-type: none; /* Removes the default numbering */
  counter-reset: my-counter; /* Initializes a custom counter */
}

ol li {
  counter-increment: my-counter; /* Increments the counter for each list item */
}

ol li::marker {
  content: counter(my-counter) '. '; /* Displays the counter value as the marker */
  color: #007bff; /* A blue color for the custom numbers */
}

Explanation

This advanced example demonstrates the use of CSS counters with the ::marker pseudo-element. It creates a custom-styled numbered list, offering more flexibility than the default ordered list styles.