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 CSS 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

Learn How to Select Only the CSS First Child

Front, Programming

The CSS nth-of-type Selector – How To Target Elements By Type

Front, Programming

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

Front, Programming

CSS Selectors nth-child VS nth-of-type And How To Use Them Correctly

Front, Programming

Coding Made Easy With CSS Selectors: An Ultimate Guide

Front, Programming

How to Center in CSS Using Different Ways

Front, Programming

What You Need to Know About CSS Color Methods

Programming

Most Common Typescript Errors and How to Solve Them

Front, Programming

Make Your Work Easier by Using Variables in CSS

Front, Programming

CSS Rainbow Text: How To Make Astonishing And Vibrant Fonts

Front, Programming

Most Useful HTML Elements for Maximizing Better Results

Back, Programming

Environment Variables 101: Secure Your Secrets Like a Pro

Subscribe to our newsletter

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

Intuit Mailchimp