Pseudo-elements (::before, ::after) are indispensable tools for reducing HTML bloat and isolating decorative styles. This collection emphasizes their technical utility in functionally replacing multiple wrapper <div>s, focusing on precise positioning and mastering the content property - from inserting strings to generating purely graphical shapes. The demos showcase advanced techniques like dynamic content generation using attr() and leveraging pseudo-elements as the primary targets for performant CSS transitions and complex @keyframes animations. Mastering this foundation is crucial for writing cleaner, more semantic markup and boosting efficiency in modern, component-based architectures.
106 CSS Pseudo Elements
Modern CSS Star Rating Component
demo & codeThis Modern CSS Star Rating Component represents a major shift in UI development, moving complex logic from JavaScript to pure CSS. It utilizes the powerful :has() selector to track sibling states, allowing the UI to highlight stars both before and after the interaction point. The stars themselves are created using clip-path instead of bulky SVG icons, resulting in a lightweight, scalable, and highly performant rating system.
Split Staggered Reveal Cards
demo & codeThis Split Staggered Reveal Card creates a dramatic, cinematic effect suitable for portfolios or featured content sections. Upon interaction, the background image recedes while two semi-transparent overlays slide in to create a high-contrast backdrop. Simultaneously, the title and description animate in with a precise staggered delay - letters for the title and words for the paragraph - powered by CSS variables.
Stylish Highlighter Link Hover Animation
demo & codeThis Highlighter Link Hover Effect provides a sophisticated micro-interaction for inline text links, moving beyond the standard static underline. By default, the link is covered by a soft, semi-transparent background fill; upon hovering, this “highlighter” block collapses into a thin underline while a directional arrow slides in from the right.
Pure CSS ASCII File Tree
demo & codeThis Pure CSS ASCII File Tree brings the nostalgia of command-line directory structures to the web without typing a single pipe character manually. By cleverly utilizing CSS pseudo-elements (::before), it automatically draws the connecting lines (│, ├, └) for nested lists. It’s perfect for technical documentation, sitemaps, or retro-themed interfaces.
Bicycle
A pure CSS bicycle illustration constructed from geometric primitives using absolute positioning and vmin units for responsiveness. conic-gradient simulates wheel spokes, transform: skewX shapes the frame, and inset box-shadow adds depth, while pseudo-elements efficiently duplicate components like wheels.
See the Pen Bicycle.
Dipper Pines from Gravity Falls
A pure CSS character illustration of Dipper Pines, constructed from geometric primitives using absolute positioning and vmin units for responsiveness. The design leverages border-radius, transform, clip-path masking, and pseudo-elements to shape detailed features like the signature pine tree hat and hair, all styled with CSS variables and a custom web font.
See the Pen Dipper Pines from Gravity Falls.
Giraffe
A pure CSS cartoon illustration of a giraffe constructed from geometric primitives using absolute positioning. It leverages box-shadow for efficient pattern repetition (spots, clouds), clip-path for complex shapes like the mane, and CSS variables for a consistent pastel color palette.
See the Pen Giraffe.
Profile CSS Drawing
A stylish, detailed vector-style portrait with depth and shadows, fully implemented using pure CSS gradients and clipping paths.
See the Pen Profile CSS Drawing.
Nested List Style
An elegant, modern list of track properties featuring custom graphic icons and smooth micro-interactions like padding shifts and color changes on hover.
See the Pen Nested List Style.
OST Tree
A pure CSS tree diagram constructed from nested lists where pseudo-elements with borders form the connecting branches.
See the Pen OST Tree.
Soft Button Styling
A collection of skeuomorphic buttons rendered entirely in CSS using complex gradient layering and calc()-driven geometry variables.
See the Pen Soft Button Styling.
Up Arrow
A rectangular button smoothly shrinks into a circle, the text fades out, and an upward-pointing arrow begins to cyclically rise within it.
See the Pen Up Arrow.
Little Details
A stylized nested to-do list employing advanced CSS pseudo-elements for custom markers and hover-based reveal logic for sub-tasks. JavaScript handles basic DOM manipulation for adding/removing items, while the dark UI features gradient borders and tooltip interactions.
See the Pen Little Details.
Pure CSS Entity Visualizer
An automated text annotation interface powered by Sass loops that visualizes semantic entity types using pseudo-elements and data attributes.
See the Pen Pure CSS Entity Visualizer.
Kinetic CSS Loader
A smooth, rhythmic, and mesmerizing loader that looks complex but is implemented simply and efficiently.
See the Pen Kinetic CSS Loader.
Skull Toggle (CSS)
A playful skeleton toggle switch animated purely with CSS. The skull handle slides via @keyframes triggered by the :checked state, while a complex hand assembly - constructed from gradients and box-shadows - slides in to “push” the toggle, creating a whimsical, interactive narrative without JavaScript.
See the Pen Skull Toggle (CSS).
List Styles
An aesthetically pleasing, modern todo list featuring a vibrant gradient theme and an intuitive hierarchy creation function without complex control buttons.
See the Pen List Styles.
Creative Section Design
A visually rich, animated section with cards that respond to hover (a colored border appears), creating a sense of interactivity and depth.
See the Pen Creative Section Design.
CSS Rage Button
A playful button that shakes, reddens, and “curses” with increasing intensity upon each click (or hover for the secondary button), visualizing a gradual loss of composure.
See the Pen CSS Rage Button.
Product Plan Cards with CSS Ribbons
A pure CSS pricing component that creates a dimensional ‘ribbon’ aesthetic solely through ::after pseudo-elements and clip-path geometry. The layout leverages CSS Custom Properties for distinct color themes and calc with negative margins to extend elements beyond the parent container, creating a folded paper effect without any JavaScript dependencies.
See the Pen Product Plan Cards with CSS Ribbons.
Pure CSS Liquid Wave Illusion
This demo creates a captivating liquid wave illusion using a single ::before pseudo-element inside multiple overflow: hidden containers. The fluid motion is the result of two simultaneous @keyframes animations - one controlling top and the other transform: rotateZ.
See the Pen Pure CSS Liquid Wave Illusion.
Metallic Skeuomorphic Toggle Switches
A skeuomorphic toggle design achieved by combining multiple linear-gradients for the body and box-shadow to create a volumetric effect. The smooth switching animation and “glow” in the active state are implemented via transition with a custom cubic-bezier curve.
See the Pen Metallic Skeuomorphic Toggle Switches.
Checkbox Hamburger Menu Animation
A demonstration of step-by-step CSS transformation to create a cross effect: on :checked, the middle bar either gets opacity: 0 or scales down, while the top and bottom bars simultaneously rotate and translate.
See the Pen Checkbox Hamburger Menu Animation.
CSS Cat Illustration with Tracking Eyes
An illustration of a cat created entirely in CSS, featuring interactive eyes that follow the cursor. JavaScript uses Math.atan2 to calculate the gaze angle, while all of the cat’s details - from the body to the whiskers - are implemented using pseudo-elements, box-shadow, and gradients.
See the Pen CSS Cat Illustration with Tracking Eyes.
Dark Mode Toggle Switch
A toggle switch implemented using a single <input type="checkbox"> and pseudo-elements. The “button” effect and its movement are achieved through complex, multi-layered box-shadow and the shifting of the ::before element.
See the Pen Dark Mode Toggle Switch.
Neon Icon Hover Effect
A navigation menu with a neon glow and a complex hover effect. Icons and text use the CSS drop-shadow filter to create a glow effect, while the element’s color is controlled via an inline CSS variable --clr.
See the Pen Neon Icon Hover Effect.
Page Indicator Animation
A full vertical slider with scroll-snap points. The navigation indicator is dynamically animated using the Intersection Observer API, which tracks when a slide enters the viewport.
See the Pen Page Indicator Animation.
Change Bass Color with Hue
A simple example of media control - a click event in vanilla JS is used both to control the HTML5 Audio API and to dynamically change the hue-rotate CSS filter.
See the Pen Change Bass Color with Hue.
Progress Button Microinteractions
An animated loader button using jQuery and SCSS, where progress is implemented via an @for loop that generates 101 linear-gradient rules - the state is changed through a custom attribute updated by JS.
See the Pen Progress Button Microinteractions.
Ticket
A ticket layout where data (date, code) is generated on the fly with vanilla JS and inserted into the HTML - styling is done using CSS Grid, drop-shadow, and reusable SVG symbols via the <use> tag.
See the Pen Ticket.
BMO CSS Illustration with nth-child
An example of creating CSS art using pseudo-elements and nth-of-type, enhanced with a JS easter egg - a mouseover spam detector to call the Vibration API.
See the Pen BMO CSS Illustration with nth-child.
CSS Hamburger Click Effect
Explore the technique of creating a three-line hamburger using a single <span> tag and two pseudo-elements, - which are then animated into an ‘X’ via a combination of CSS properties rotate(45deg) and translate.
See the Pen CSS Hamburger Click Effect.
FAQ Accordion with Font Awesome Icons
The “Accordion/FAQ” functionality is implemented using pure JavaScript, which handles the click on the parent element and toggles the active class on the FAQ container. The visual highlight is the icon change via CSS display: none/block properties.
See the Pen FAQ Accordion with Font Awesome Icons.
Gender Toggle Button with Bounce Effect
This interactive toggle switch demonstrates advanced animation work, where delayed class toggling in jQuery coordinates the knob movement and a stylish “color fill” text effect, created in CSS using overflow: hidden; and pseudo-elements.
See the Pen Gender Toggle Button with Bounce Effect.
Neumorphic Multi-Buttons with CSS Feedback
An effective button group where the hover effect is created via inset box-shadow - and the click confirmation animation is implemented using transform and opacity on the ::after pseudo-element.
See the Pen Neumorphic Multi-Buttons with CSS Feedback.
Simple YouTube API Search App
A simple search client for the YouTube API written in vanilla JS - data is fetched using fetch, and the results list is generated on the fly and injected into the DOM via innerHTML.
See the Pen Simple YouTube API Search App.
Vue Add to Cart Animation
This Vue.js component showcases a clean implementation of the “Add to Cart” micro-interaction using reactive data and CSS animation. The main technical feature is the dynamic counter display via a CSS ::before pseudo-element and the count attribute, alongside the “Pop” effect upon update.
See the Pen Vue Add to Cart Animation.
Animated UI Radio Button with CSS Keyframes
This custom radio button UI employs pure CSS @keyframes and transform properties to create a dynamic, liquid-like squash-and-stretch animation upon selection - the smooth UI transition is managed by complex jQuery state logic that precisely adds and removes animation classes.
See the Pen Animated UI Radio Button with CSS Keyframes.
Art Deco Card
An elegant Art Deco style card created purely with CSS/SCSS, utilizing a sophisticated technique with pseudo-elements to construct complex, multi-layered geometric borders and corners.
See the Pen Art Deco Card.
Lighthouse Single-Div CSS Illustration
The entire scene is constructed from a combination of gradients (linear-gradient/radial-gradient) and precise element positioning using background-position.
See the Pen Lighthouse Single-Div CSS Illustration.
Card with Glitch Effect
This Cyberpunk-inspired card features a complex box-shadow offset and text-shadow for the core CRT aesthetic, paired with a dynamic :hover state that uses transform to instantly swap the terminal view for a social icon grid.
Button
The main button has a semi-transparent background, the ::before pseudo-element contains the animated gradient, and ::after has a solid dark background that “cuts out” the inner part, leaving only the border visible.
Fancy Title with CSS Responsive Frame
Creating a complex decorative title where breaks in the border are elegantly implemented using CSS Grid and pseudo-elements. Padding sizes adapt dynamically thanks to a CSS variable calculated by a mixin.
See the Pen Fancy Title with CSS Responsive Frame.
Virtual Credit Card UI
A demonstration of “living” cards with two looped @keyframes animations - one for smooth background panning, and another for creating a shimmering gradient highlight.
Rainbow Shadow Button
Featuring a modern aesthetic, this button generates a soft aura using a blurred and offset pseudo-element whose color dynamics are precisely controlled by the oklch function and longer hue interpolation within the linear-gradient.
See the Pen Rainbow Shadow Button.
Inverted Border Boxes
A demonstration of a non-trivial technique for creating inverted rounded corners using ::before pseudo-elements and box-shadow. This trick allows you to “carve out” complex shapes from parent blocks, bypassing the limitations of standard border-radius.
See the Pen Inverted Border Boxes.
Arrow Icon Animation
A technically advanced use of ::before and ::after pseudo-elements to create an arrow. jQuery toggles the .right class, and CSS animates the left and transform: rotate() properties of the pseudo-elements, creating a “switch” or 3D flip effect.
See the Pen Arrow Icon Animation.
Bootstrap 5 Breadcrumb Example
A chevron-style Bootstrap customization where SCSS darken creates a gradient depth. The geometry relies on ::after border hacks, with :nth-child controlling color progression and z-index stacking.
See the Pen Bootstrap 5 Breadcrumb Example.
Custom Bootstrap Accordion with Plus/Minus
A bold, high-contrast process accordion customized on top of Bootstrap.
See the Pen Custom Bootstrap Accordion with Plus/Minus.
Eye-Catching Bootstrap 5 Button
A vibrant CTA button featuring a neon linear gradient and a continuous ‘shine’ animation implemented via a moving radial gradient on the ::before pseudo-element. On hover, it scales up and intensifies its colored drop-shadow for enhanced interactivity.
See the Pen Eye-Catching Bootstrap 5 Button.
Simple Subscribe Form
This demo’s lively backdrop is created by injecting animated creatures into the form’s ::before and ::after pseudo-elements using Base64 data:image URLs. This visual flair is complemented by polished, pure CSS micro-interactions - the email input elegantly expands its width on :focus, while the submit button provides a tactile 3D press effect by manipulating box-shadow and transform: translateY().
See the Pen Simple Subscribe Form.
Pure CSS Star Rating from 0 to 8 with Colored Points of the Star
This star rating component is a showcase of static state management using a modular, class-based system. The rating is set by applying classes like .one and .half to the main container, which then declaratively styles the individual points of the star without any JavaScript or form inputs.