🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
Introduction
A text stroke (outline) effect in CSS adds a border around each letter, making the text stand out. This can be achieved using the -webkit-text-stroke property. The stroke effect outlines the text without affecting its fill color, making it a popular design technique for creating bold, impactful text.
In this tutorial, you'll learn how to create a text stroke effect using HTML and CSS.
Problem Statement
Create a CSS code that:
- Adds a stroke (outline) effect to text using the
-webkit-text-strokeproperty. - Demonstrates how to control the stroke's width and color.
Example:
- Input: A heading element with the text "Text Stroke Effect".
- Output: The text appears with an outline or stroke around each character.
Solution Steps
- Use
-webkit-text-strokeProperty: Apply the-webkit-text-strokeproperty to add an outline around the text. - Control Stroke Width and Color: Set the width and color of the stroke to customize the appearance.
HTML Structure
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text Stroke Effect</title>
<style>
/* Step 1: Create text stroke effect */
.stroked-text {
font-size: 4rem;
font-weight: bold;
color: white; /* Text fill color */
-webkit-text-stroke: 2px black; /* Stroke width and color */
text-align: center;
font-family: Arial, sans-serif;
}
/* Center the text container */
.container {
text-align: center;
margin-top: 100px;
background-color: #333; /* Background for contrast */
padding: 50px;
}
</style>
</head>
<body>
<div class="container">
<h1 class="stroked-text">Text Stroke Effect</h1>
</div>
</body>
</html>
Explanation
Step 1: Use -webkit-text-stroke for the Stroke Effect
To create a text stroke effect, use the following CSS:
.stroked-text { font-size: 4rem; font-weight: bold; color: white; /* Text fill color */ -webkit-text-stroke: 2px black; /* Stroke width and color */ }The
-webkit-text-strokeproperty defines both the stroke width and the stroke color. In this case, the stroke is2pxwide and black, while the text itself is filled with white.
Step 2: Customize the Stroke Width and Color
- You can change the stroke's width and color by adjusting the value of the
-webkit-text-strokeproperty. For example, to create a thicker stroke, you can increase the pixel value:-webkit-text-stroke: 4px red; /* Example with a 4px red stroke */
Step 3: Set Background Color for Contrast
- The dark background (
#333) helps the white text and black stroke stand out, making the stroke effect more visually striking.
Output
Conclusion
Creating a text stroke (outline) effect in CSS is straightforward using the -webkit-text-stroke property. You can easily customize the stroke's width and color to achieve bold and visually appealing text effects, making your text stand out on the page.
My Top and Bestseller Udemy Courses. The sale is going on with a 70 - 80% discount. The discount coupon has been added to each course below:
Build REST APIs with Spring Boot 4, Spring Security 7, and JWT
[NEW] Learn Apache Maven with IntelliJ IDEA and Java 25
ChatGPT + Generative AI + Prompt Engineering for Beginners
Spring 7 and Spring Boot 4 for Beginners (Includes 8 Projects)
Available in Udemy for Business
Building Real-Time REST APIs with Spring Boot - Blog App
Available in Udemy for Business
Building Microservices with Spring Boot and Spring Cloud
Available in Udemy for Business
Java Full-Stack Developer Course with Spring Boot and React JS
Available in Udemy for Business
Build 5 Spring Boot Projects with Java: Line-by-Line Coding
Testing Spring Boot Application with JUnit and Mockito
Available in Udemy for Business
Spring Boot Thymeleaf Real-Time Web Application - Blog App
Available in Udemy for Business
Master Spring Data JPA with Hibernate
Available in Udemy for Business
Spring Boot + Apache Kafka Course - The Practical Guide
Available in Udemy for Business
%20Effect%20with%20HTML%20and%20CSS.png)
Comments
Post a Comment
Leave Comment