How To Add Strike Through On Text In React Native ?
Last Updated :
23 Jul, 2024
In this article, we will explore two different approaches to adding a strike-through effect to text in React Native. It is also known as crossed-out text used to display the text as cross-marked.
Prerequisites
- Introduction to React Native
- React Native Components
- React Hooks
- Expo CLI
- Node.js and npm
Syntax
<Text style={{ textDecorationLine: 'line-through' }}>Original Price: $50</Text>
Steps to Create React Native Application
Step 1: Create React Native Application With Expo CLI
Create a new React Native project for <<Project Name>>.
npx create-expo-app <<Project Name>>
Step 2: ​Change the directory to the project folder:
cd <<Project Name>>
Project Structure

Approach 1: Using CSS styling
In this approach, we'll add a strike-through effect to a product card's original price using CSS styles.
Example 1: This React Native example showcases an product card that combines fetching an image from a URL. The card rounded corners, a white backgÂround, and a shadow. To indicate a discount, the original price is displayed with a striking red strike-through effect, while the sell price is presented in black.
JavaScript
// App.js file
import React from "react";
import {
Text,
View,
StyleSheet,
Image,
} from "react-native";
function App() {
// Replace with your image URL
const imageUrl =
"https://media.geeksforgeeks.org/wp-content/uploads/20230816223829/geeksgforgeeks-logo-1.png";
return (
<View style={styles.card}>
<Image
source={{ uri: imageUrl }}
style={styles.image}/>
<View style={styles.details}>
<Text style={styles.title}>
Product Name
</Text>
<Text style={styles.price}>
Original Price: $50
</Text>
<Text style={styles.sellprice}>
Sell Price: $40
</Text>
</View>
</View>
);
}
const styles = StyleSheet.create({
card: {
margin: 25,
backgroundColor: "#ffffff",
borderRadius: 10,
shadowColor: "black",
shadowOffset: {
width: 1,
height: 3,
},
shadowOpacity: 1,
shadowRadius: 15,
elevation: 5,
overflow: "hidden",
},
image: {
width: "100%",
height: 200,
resizeMode: "cover",
},
details: {
padding: 16,
},
title: {
fontSize: 20,
fontWeight: "bold",
marginBottom: 8,
},
price: {
fontSize: 18,
//Strikethrough
textDecorationLine: "line-through",
color: "red",
},
sellprice: {
fontSize: 20,
color: "black",
padding: 5,
},
});
export default App;
Step 3: To launch the React native application, navigate to the terminal or command prompt and execute the necessary command.
npx expo start
npx react-native run-android
npx react-native run-ios
Output:

In this approach, we'll create a product card, featuring an original priceÂ. when the user clicks on a button, , the original price will appear with a visually striking line across it.
Example 1: In this example, we are using the useState hook that to allow us for toggling between displaying an original price and a discounted price. The card consists of an image, the name of the product, and a button that facilitates switching betweeÂn prices. The image is reÂtrieved from a specifieÂd URL, while the card's appearance is enhanced using featureÂs like a white background, rounded corneÂrs, shadows, and appropriately formatted text. By preÂssing the button, users can seamleÂssly alternate betweÂen viewing the original price with a strike-through effect—a feÂature designed to facilitate easy comparison of prices.
JavaScript
// App.js file
import React, { useState } from "react";
import {
Text,
View,
Button,
StyleSheet,
Image,
} from "react-native";
function App() {
const [strikeThrough, setStrikeThrough] =
useState(false);
const toggleStrikeThrough = () => {
setStrikeThrough(!strikeThrough);
};
// Replace with your image URL
const imageUrl =
"https://media.geeksforgeeks.org/wp-content/uploads/20230816223829/geeksgforgeeks-logo-1.png";
return (
<View style={styles.card}>
<Image
source={{ uri: imageUrl }}
style={styles.image}/>
<View style={styles.details}>
<Text style={styles.title}>
Product Name
</Text>
<Text
style={
strikeThrough
? styles.strikeThroughPrice
: styles.price}>
{strikeThrough
? "Original Price: $50"
: "Discounted Price: $40"}
</Text>
<Button
title="See Original Price"
onPress={toggleStrikeThrough}/>
</View>
</View>
);
}
const styles = StyleSheet.create({
card: {
backgroundColor: "#ffffff",
borderRadius: 10,
shadowColor: "#000",
shadowOffset: {
width: 1,
height: 3,
},
shadowOpacity: 1,
shadowRadius: 15,
elevation: 5,
margin: 25,
overflow: "hidden",
},
image: {
width: "100%",
height: 200,
resizeMode: "cover",
},
details: {
padding: 16,
},
title: {
fontSize: 20,
fontWeight: "bold",
marginBottom: 8,
},
price: {
fontSize: 18,
color: "black",
},
strikeThroughPrice: {
fontSize: 18,
textDecorationLine: "line-through",
color: "red",
},
});
export default App;
Output:
Similar Reads
How To Add Strikethrough On Text In ReactJs ?
Strikethrough text is a visual representation often used to denote changes or deleted content within an application. In this article, we will see various techniques to effectively add a strikethrough to Text using ReactJs. Strikethrough text, also referred to as crossed-out or deleted text serves as
4 min read
How to add SearchBar in React Native ?
In this article we'll add search functionality in React-Native. This can be regarded as a continuation to React native flatlist component/. In the aforementioned article we created a flatlist using Flatlist component, let's make it searchable using SearchBar component. To add a SearchBar to your fla
5 min read
How to add a Touchable Ripple in react-native ?
React Native is a framework developed by Facebook for creating native-style apps for iOS & Android under one common language, JavaScript. Initially, Facebook only developed React Native to support iOS. However, with its recent support of the Android operating system, the library can now render m
2 min read
How to Strike Through Text When Checking a Checkbox in ReactJS ?
In this article, we are going to learn about strike-through text when checking a checkbox. Strike through text when checking a checkbox in React-Bootstrap refers to the functionality of applying a strikethrough style to text when a corresponding checkbox is checked. It is commonly used to visually i
3 min read
How to Copy Text to the Clipboard in React Native ?
Mobile app deÂvelopment requires enabling text copying to the clipboard for seÂamless content sharing and improved useÂr experienceÂ. A popular cross-platform framework, React Native, offers a solution to this common requirement. This article will guide developeÂrs through implementing clipboard fun
3 min read
How to Add Tag Input in React Native ?
Tags are widely used for managing items or categories in UI. Adding a tag input feature in React Native allows users to dynamically add and remove tags, enhancing data organization and filtering in applications. In this article, we will see how we can add tag input in react native application. We ar
4 min read
How to Show and Hide Password in React Native ?
In this article, we'll see how we can add password show and hide features in React Native applications. In mobile apps, users often need to toggle password visibility for better user experience and accuracy. React Native simplifies this with the `SecureTextEntry` prop in the `TextInput` component, e
3 min read
How to add Share button in React Native ?
React Native is an open-source UI software framework created by Meta Platforms, Inc. It is used to develop applications for Android, Android TV, iOS, macOS, tvOS, Web, Windows, and UWP by enabling developers to use the React framework along with native platform capabilities. In this article, we will
2 min read
How to create a Surface in react-native ?
React native is a framework developed by Facebook for creating native-style apps for iOS & Android under one common language, JavaScript. Initially, Facebook only developed React Native to support iOS. However, with its recent support of the Android operating system, the library can now render m
3 min read
How to create toast in React Native ?
React Native is an open-source UI software framework created by Meta Platforms, Inc. It is used to develop applications for Android, Android TV, iOS, macOS, tvOS, Web, Windows, and UWP by enabling developers to use the React framework along with native platform capabilities. In this article, we will
2 min read