How to Add Text Shadow in Tailwind CSS?
Last Updated :
10 Oct, 2024
Adding a text shadow in Tailwind CSS is useful for making text for creating visual effects like glows and embossed or debossed effects. Tailwind CSS does not provide text shadow utilities out of the box but it allows you to easily extend its functionality to add custom utilities. In this article, we will explore how to add a text shadow in a project using Tailwind CSS.
Approach
- Begin the project by creating a React application and installing Tailwind CSS along with its dependencies.
- Modify the
tailwind.config.js
file to include a custom plugin. Within this plugin, define the text-shadow styles you want to support, such as various shadow sizes and colors. - Once the custom utilities are defined, you can apply them directly in your React components using the classes you created, allowing for easy integration of text shadows throughout your application.
- Finally, run the application to see the text-shadow effects in action, making adjustments as needed to perfect the styles.
Prerequisites
Steps To Add Text Shadow
Step 1: Set up a React Application
npx create-react-app react-app
cd react-app
Step 2: Install Tailwind CSS using the command
npm install -D tailwindcss postcss autoprefixernpx tailwindcss init -p
Step 3: Configure the tailwind paths in your tailwind.config.js file
module.exports = {
content: ["./src/**/*.{js,jsx,ts,tsx}"],
theme: {
extend: {
colors: {
primaryGreen: "#4CAF50", // Green
primaryBlack: "#000000", // Black
primaryWhite: "#FFFFFF", // White
}
},
},
plugins: [],
}
Step 4: Add tailwind directives to your index.css file
@tailwind base;
@tailwind components;
@tailwind utilities;
body {
margin: 0;
font-family: 'Times New Roman', Times, serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
Project Structure:
Project structureUpdated Dependencies:
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-icons": "^5.3.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
}
Example: This example demonstrates the creation of text shadow using React and Tailwind CSS
JavaScript
// App.js
import React, { useState } from "react";
function App() {
return (
<div className="flex items-center justify-center min-h-screen bg-green-100">
<ul class="space-y-8 w-full h-96 p-8 flex items-center justify-center
gap-2 flex-col bg-inherit rounded-xl">
<li class="[text-shadow:_0_2px_4px_rgb(99_102_241_/_0.8)]
text-indigo-600 text-xl md:text-2xl leading-snug
font-manrope font-extrabold">Text Shadow: Small
</li>
<li class="[text-shadow:_0_4px_4px_rgb(99_102_241_/_0.8)]
text-indigo-600 text-xl md:text-2xl leading-snug
font-manrope font-extrabold">Text Shadow: Default
</li>
<li class="[text-shadow:_0_8px_8px_rgb(99_102_241_/_0.8)]
text-indigo-600 text-xl md:text-2xl leading-snug
font-manrope font-extrabold">Text Shadow: Large
</li>
<li class="[text-shadow:_0_4px_8px_#00BCD4] text-[#00BCD4]
text-xl md:text-2xl leading-snug font-manrope
font-extrabold">Text Shadow: Arbitrary (Custom Color)
</li>
<li class="[text-shadow:_0_4px_8px_rgba(14_165_223_/_0.5)]
text-sky-400 text-xl md:text-2xl leading-snug
font-manrope font-extrabold"> Text Shadow: Arbitrary
(Tailwind CSS Color)
</li>
</ul>
</div>
);
}
export default App;
Step 4: Run the Application
npm start
Output:
outputConclusion
This article showcases the flexibility of Tailwind CSS and its extensibility through custom utilities such as adding text shadows. By extending the default configuration we can introduce new styling options that are not available out of the box. We also demonstrated how JavaScript can be integrated with Tailwind to dynamically manipulate styles and adding interactivity to a static webpage.
Similar Reads
Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav
11 min read
Web Development Web development is the process of creating, building, and maintaining websites and web applications. It involves everything from web design to programming and database management. Web development is generally divided into three core areas: Frontend Development, Backend Development, and Full Stack De
5 min read
Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
React Interview Questions and Answers React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications
15+ min read
React Tutorial React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version
7 min read
JavaScript Interview Questions and Answers JavaScript is the most used programming language for developing websites, web servers, mobile applications, and many other platforms. In Both Front-end and Back-end Interviews, JavaScript was asked, and its difficulty depends upon the on your profile and company. Here, we compiled 70+ JS Interview q
15+ min read
Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read
3-Phase Inverter An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power
13 min read