Card: Pseudo Elements

Pseudo-Elements

The Secret Tricks of CSS Wizards

In the dim, shadowy corners of CSS, pseudo-elements dwell like invisible magicians, quietly casting their spells without ever being seen. While ordinary HTML elements dutifully follow instructions, pseudo-elements appear when you need something extraordinary.

They materialize out of thin air, adding weight to the first letter of a paragraph, conjuring content before or after an element, or transforming list bullets into magical symbols. These subtle yet powerful spells elevate your design from “nice” to “wow!” They work seamlessly behind the scenes, adding depth and flair to your creations without complicating the HTML structure.

Pseudo-Elements – More Than Meets the Eye

Decorate text or target the first letter with style!

Token: first-letter

::first-letter

The Beginning of Every Tale

The ::first-letter spell brings special attention to the first letter of your text. You can make it bigger, bolder, or transform it into a majestic character straight out of ancient manuscripts. It’s the perfect way to pull readers into the story. With ::first-letter, a simple beginning becomes an epic event!

p::first-letter {
    font-size: 2em;
}

This CSS enlarges the first letter of each paragraph to twice the font size (2em) and visually emphasizes it.

Token: first-line

::first-line

The Prologue of the First Line

With ::first-line, you can add a magical touch to the opening line of any text block. This pseudo-element grabs the first line and enchants it with colors, font sizes, or even a unique background. It’s like the introductory chant of a wizard.

p::first-line {
    font-weight: bold;
    color: brown
}

This CSS styles the first line of each paragraph bold and brown.

Token: before

::before

The Harbinger of Content

::before acts as a loyal herald, standing before your element like a messenger that appears just before the main content. It allows you to add content that doesn’t exist in the HTML, making it seem as if it was always there.

h1::before {
    content: "★ ";
}

This CSS adds a star symbol before each <h1> element to visually enhance the title.

Token: after

::after

The Final Flourish

If ::before is the herald, then ::after is the encore that lingers after the grand finale. It lets content appear after the main text, as if a narrator adds one final note to leave a lasting impression.

h1::after {
    content: " ★";
}

This CSS appends a star symbol after each <h1> element’s content to visually round off the title.

Token: marker

::marker

The List Mark Enchanter

With ::marker, you can take control of list markers. Why settle for ordinary dots or dashes when you can turn them into glowing symbols or enchanting colors? Transform mundane list points into something extraordinary.

ul li::marker {
    color: green;
    content: "→";
}

This CSS makes list markers green and replaces them with arrows.

Token: selection

::selection

The Flickering Magic of Highlights

When someone selects text on your page, it should feel magical. ::selection lets you enchant the highlighted area, making it shine with vibrant colors when a user drags their mouse over it. No more dull gray—just bold, dazzling brilliance! With ::selection, even the act of selecting text becomes an illuminating experience!

::selection {
    background: green;
    color: black;
}

Selected text is given a green background and black font color.

CSS
/* Pseudo-Elements for the container */
.container::before {
    content: "⚔️ Die Geheimnisse der Festung";
    display: block;
    text-align: center;
    font-size: 1.8rem;
    margin-bottom: 15px;
    color: #ffd700;
    text-shadow: 0 2px 5px rgba(0, 0, 0, 0.8);
}

.container::after {
    content: "💫 Endstation der Dunkelheit";
    display: block;
    text-align: center;
    font-size: 1.2rem;
    margin-top: 20px;
    color: #ff6f61;
    text-shadow: 0 2px 5px rgba(0, 0, 0, 0.6);
}

/* Style paragraphs */
p {
    font-size: 1.1rem;
    text-align: justify;
}

p::first-letter {
    font-size: 2.5rem;
    font-weight: bold;
    color: #6df0c2;
    text-shadow: 0 3px 5px rgba(0, 0, 0, 0.6);
}

p::first-line {
    font-style: italic;
    color: #82b4f5;
}

/* List with marker */
.secret-list {
    padding-left: 30px;
    margin-top: 20px;
}

.secret-list::marker {
    content: "🔑";
    color: #ffa726;
}

.secret-list li {
    font-size: 1.1rem;
    margin-bottom: 10px;
    transition: color 0.3s ease, transform 0.3s ease;
}

.secret-list li:hover {
    color: #ffd700;
    transform: translateX(10px);
}

/* text selection */
::selection {
    background-color: #283593;
    color: #f0f0f5;
}
Scroll to Top