CSS Pseudo Classes are an excellent way to add design accents to your website without adding extra HTML elements. This tutorial will show you how to use CSS pseudo elements ::before
and ::after
to create accent lines next to your headings.
Adding the Class to Your HTML Element
Navigate to the HTML element you want to style, such as a heading, and add the class accent-lines
.
<h2 class="accent-lines">Get Support</h2>
Writing the Combined CSS
Open your CSS file or customizer and write the CSS for the ::before
and ::after
pseudo elements. Here’s how to combine all the properties into one CSS code block:
.accent-lines::before, .accent-lines::after { content: ""; width: 20px; border-bottom: 1px solid red; margin: auto; } .accent-lines::before { margin-right: 0.5em; } .accent-lines::after { margin-left: 0.5em; }
Customizing Your Design
Feel free to adjust the width, color, and margins to fit your design needs. For example, you can change the width to 40px
and the color to light gray
.
.accent-lines::before, .accent-lines::after { width: 40px; border-bottom: 1px solid lightgray; }
Supplementary Resources
Conclusion of CSS Pseudo Classes
Using CSS Pseudo Classes for design accents is a clean and efficient method. By following this tutorial, you can easily add stylish accents to your headings or any other elements on your website.