How to Create a Marker Underline Effect for Text Codepen with CSS

Author

Reads 781

A Person Holding a Marker
Credit: pexels.com, A Person Holding a Marker

Creating a marker underline effect for text on CodePen requires a combination of HTML and CSS. To start, you'll need to add a span element to your HTML code to create a container for the underline effect.

The CSS code will be used to style this span element and create the marker underline effect. In the CSS code, you'll use the :before pseudo-element to add a line before the text, which will serve as the underline.

To customize the appearance of the underline, you can adjust the CSS properties, such as the background color, height, and position.

Methods

To create a marker underline effect, you'll need to use CSS. This involves adding a line of code to your stylesheet to define the style of the underline.

The CSS property you'll use is `text-decoration`, which allows you to add a line under the text. By setting `text-decoration` to `underline`, you can create a simple underline effect.

Credit: youtube.com, How To Underline Text In After Effects? - The Animation Reel

You can also use the `border-bottom` property to create a marker underline effect. This involves adding a border to the bottom of the element, which can be styled to match your desired effect.

To use `border-bottom`, you'll need to specify the color, width, and style of the border. For example, you can use `border-bottom: 1px solid #000` to add a black border to the bottom of the element.

Effects

You can create a CSS hover effect like no other, just like the examples show.

There's more than one way to create the CSS underline effect for your page links, and you can get as elaborate as you please.

You can recreate the CSS underline effects shown in examples yourself.

The elegance of simplicity is an argument that holds some truth, especially when it comes to creating a CSS hover effect.

Advanced Techniques

To create a marker underline effect, you can use background-image as it allows spanning multiple lines. This method is especially useful for creating underlines that span over several lines of text.

Credit: youtube.com, Most people have no idea you can style underlines like this

You can change the second value in background-position to adjust how far from the top the underline should be, such as setting it to 0 100% to position the underline at the bottom of the text.

To make the underline appear only on hover, set the background-size to a zero width and a 2px height, and then transition the background-size to change the width to 100% on hover. This will create a full underline that animates into view.

You can also use actual images, such as SVG or PNG, to style CSS underlines, but using a linear gradient can be a more efficient option for creating a simple line.

CSS Properties

The text-decoration property is a shorthand property for three other properties: text-decoration-line, text-decoration-style, and text-decoration-color. It's the most straightforward way to underline text, but it lacks customizability.

You can use text-decoration: none to remove the underline, and text-decoration: overline, underline, underline overline, or line-through to create different types of underlines. The text-decoration-style property allows you to add a style to the underline, such as solid, dotted, dashed, wavy, or double.

The text-decoration-color property lets you choose the color of the underline, and you can use values like #ccc, blue, currentColor, or inherit.

Color Change

Credit: youtube.com, CSS background-color Property | Set Background color - CSS Tutorial 53 🚀

Color Change is a powerful feature in CSS that can add an extra layer of visual interest to your designs.

You can change the color of text using the color property, as seen in the example from Tapajyoti Bose, who incorporates a color transition effect.

By using the color property, you can specify a new color for the text, making it stand out or match your website's branding.

For example, Tapajyoti Bose's example uses a color transition effect, showing how you can smoothly change the color of text over time.

This can be a great way to draw attention to important information or create a sense of visual flow on your website.

CSS Text-Decoration Property

The text-decoration property is a shorthand property for three other properties: text-decoration-line, text-decoration-style, and text-decoration-color.

You can use text-decoration-line to specify the type of line you want to add, such as an overline, underline, or line-through.

The text-decoration-style property allows you to customize the style of the line, with options like solid, dotted, dashed, wavy, or double.

You can also use text-decoration-color to specify the color of the line, using a hex code, color name, currentColor, or inherit.

To remove the underline, simply use text-decoration: none.

If you want to add CSS underline on hover only, you can use the CSS rules:

Writing and Positioning

Credit: youtube.com, How to Create Awesome Underline Hover Effect with HTML and CSS

Writing and Positioning is where things get interesting. Having a vertical writing mode can affect the position of the underline, changing the direction of the offset applied on the element.

This means you need to consider the writing mode when creating your marker underline effect. Play with the values in a demo to see how it works.

The position of the underline can also be influenced by the text-underline-position property.

Using Images as CSS Backgrounds

You can use images as CSS backgrounds to style underlines, adding a creative touch to your design.

The text-decoration property is a shorthand property for three other properties, but using images as underlines offers more customizability.

To create a star-shaped CSS underline, you can use an actual image, like an SVG or PNG, as shown in John D. Jameson's CodePen example.

For a heart-shaped underline, you can use a similar approach, using an image to style the underline.

Credit: youtube.com, CSS Background Image Properties: Background Position, Size, Repeat, Color Explained

You can also use images as underlines by setting the background-image property to the image file, as demonstrated in the article.

Here are some key properties to consider when using images as CSS underlines:

By using images as underlines, you can add a unique touch to your design and make it stand out.

Box-Shadow Animation

You can create an underline with the box-shadow property that attaches a shadow to an HTML element.

This property is useful for adding visual interest to your website, and it can be especially effective when used in conjunction with other styling techniques.

To create a box-shadow animation, you can increase the vertical offset on hover by adding a second shadow with a greater vertical offset.

Here's an example of how you can use the box-shadow property to create an underline:

  • inset changes the shadow from an outer shadow (outset) to an inner shadow
  • 0 -30px 0 rgba(50,85,127,0.5): 0 is the horizontal offset, -30px the vertical offset, 0 the blur radius, and rgba(50,85,127,0.5) is a half-transparent (0.5 opacity) shade of blue
  • 0 2px 0 rgba(50,85,127,0.5): 0 is the horizontal offset, 2px the vertical offset, 0 the blur radius

By using these values, you can create a smooth and seamless animation that enhances the user experience.

Writing Modes and Text Position

Credit: youtube.com, #121 Writing Modes - The Web Dev's Toolkit: HTML, CSS, and JavaScript

Writing Modes and Text Position can greatly affect how your text looks. Having a vertical writing mode changes the position of the underline.

The direction of the underline's offset is also affected by writing modes. This can be seen in demos where values are played with.

In vertical writing modes, the underline's position changes accordingly. This is a key consideration when designing text layouts.

Elaine Block

Junior Assigning Editor

Elaine Block is a seasoned Assigning Editor with a keen eye for detail and a passion for storytelling. With a background in technology and a knack for understanding complex topics, she has successfully guided numerous articles to publication across various categories. Elaine's expertise spans a wide range of subjects, from cutting-edge tech solutions like Nextcloud Configuration to in-depth explorations of emerging trends and innovative ideas.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.