CSS Text Outline: How To Make Amazing Outlined Texts

Marilena

By Marilena

3 min read
Bookmark this post

Hello, there 😃 Let’s step into a digital world where CSS brings forth the captivating CSS text outline effect. It’s a simple yet powerful technique that adds structure and clarity to texts and elements.

Let’s dive into how CSS outlines 🖋 can make a significant difference in the visual appeal of your website. 💻 🫧

Create basic HTML and CSS structure

As a first step, we need some basic HTML structure to apply our stylings.

<body>
  <div class="outline-effect">outline effect</div>
</body>
HTML
/* insert google fonts */
@import url(
  'https://fonts.googleapis.com/css2?family=Emilys+Candy&display=swap'
);

body {
  background-color: purple;
}

.outline-effect {
  width: 650px;
  font-size: 180px;
  text-align: center;
  font-family: 'Emilys Candy', cursive;
}
CSS

Let’s see what we have done so far. I have chosen a vibrant purple color for our background while keeping the text in the default black color. Our text is set to 180px, perfectly aligned to the center.

To give a playful and lively vibe to our design, I’ve chosen the “Emily Candy” font-family which adds a delightful touch. If you also intend to use this font family, importing it into your CSS file is essential. Ensure the @import statement is placed at the beginning of your CSS code snippet, just like I did (check above lines 2-4).

In the image below, you can see the current rendering on the screen up to this point.

Apply the CSS text outline effect

.outline-effect {
  ...
  text-stroke: 2px #8695e9; // medium blue shade
  color: transparent;
}
CSS

The first thing we have to do is set the text-stoke property which represents a specific style line. Here, in our example, the text should have a light to medium blue color (#8695e9) outline with 2 pixels wide. Remember that as we increase the pixels, the outline becomes wider.

🔖 It’s useful to know that we can split the text-stroke property in two: text-stroke-width and text-stroke-color.

/* 1st choice */
  text-stroke: 2px #8695e9;

/* 2nd choice */
  text-stroke-width: 2px;
  text-stroke-color:  #8695e9;
CSS

(Personally, I opt for the shortened form, saving time and extra lines of code, but the choice is yours. 🙂)

Finally, by adding color: transparent we complete our effect by allowing the background to show through.

So, to sum up, this code styles a piece of text with a see-through center and a visible shade of blue 2px outline. It’s simple yet impressive 🎈 ✨

🌼 Hope you found my post interesting and helpful. Thanks for being here! 🌼

DigitalOcean Referral Badge
guest
0 Comments
Inline Feedbacks
View all comments

Continue reading

Front, Programming

What You Need to Know About CSS nth child Selector – A Practical Guide

Front, Programming

Learn How to Select Only the CSS First Child

Front, Programming

Grayscale Backdrop Filter: A Useful Tool To Make Grayish Backgrounds

Front, Programming

How To Calculate CSS Line Height

Front, Programming

Coding Made Easy With CSS Selectors: An Ultimate Guide

Front, Programming

Most Useful HTML Elements for Maximizing Better Results

Front, Programming

CSS Box Sizing – Better Implementations, Less Headaches

Front, Programming

What Is the CSS Box Model in Simple Terms

Front, Programming

CSS Text Decoration In Action: A Powerful Guide

Front, Programming

HTML Formatting Elements Made Simple: With Easy And Practical Examples

Front, Programming

How To Be Creative With Different CSS Border Styles

Front, Programming

How To Work With CSS Syntax: The Correct Way!

Subscribe to our newsletter

Dive into the Fun Side of Tech! Posts, News, and More Delivered to Your Inbox!

Intuit Mailchimp