Search
Close this search box.
Course Content
CSS Basic
0/1
CSS Selectors
0/1
CSS Comments
0/1
CSS Backgrounds
0/1
CSS Borders
0/1
CSS Outline
0/1
CSS Fonts
0/1
CSS Height and Width
0/1
CSS Margins and Paddings
0/2
CSS Icons
0/1
CSS Links
0/1
CSS Lists
0/1
CSS Tables
0/1
CSS Display Properties
0/1
CSS Max-Width Property
0/1
CSS Positioning Elements
0/1
CSS Z-Index Property
0/1
CSS Overflow
0/1
CSS Float
0/1
CSS Opacity
0/1
CSS Forms
0/1
CSS Dropdowns
0/1
CSS Buttons
0/1
CSS Media Queries
0/1
About Lesson

CSS pseudo-elements are used to style specific parts of an element. They allow you to style elements based on their content or position in the document without adding extra markup to the HTML. Pseudo-elements are denoted by double colons (::) preceding the element name.

These pseudo-elements allow you to insert content before or after an element’s content, respectively.

Example:

HTML
<div class="box">Content</div>
CSS
.box::before {
      content: "Before";
      color: red;
    }
.box::after {
      content: "After";
      color: blue;
    }

These pseudo-elements allow you to style the first line or the first letter of a block-level element, respectively.

Example:

HTML
<p>This is a sample paragraph.</p>
CSS
p::first-line {
      color: red;
      font-weight: bold;
    }
p::first-letter {
      font-size: 150%;
    }

This pseudo-element allows you to style the portion of text selected by the user.

Example:

HTML
<p>Select this text to see the effect.</p>
CSS
 ::selection {
      background-color: yellow;
      color: black;
    }

This pseudo-element is used to style the marker of a list item.

Example:

HTML
<ul>
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
  </ul>
CSS
 li::marker {
      content: ""; /* Custom marker */
      color: red;
    }

This pseudo-element is used to style the placeholder text in an input field or textarea.

Example:

HTML
<input type="text" placeholder="Enter your name">
CSS
 input::placeholder {
      color: gray;
      font-style: italic;
    }