How to strike through text when checking a Checkbox using HTML CSS and JavaScript ? Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will learn how to apply strikethrough to a paragraph text when a checkbox is selected using HTML, CSS, and JavaScript. This is an interactive user-friendly effect and can be used on any web page. Here, we have included a code that simply creates a card with a checkbox, when you click on the checkbox, your text will immediately be strike-through. Preview ApproachCreate a card using HTML tags and by using the <input> element of the type checkbox to display the icon and for writing text inside the card.Add style through internal CSS inside <head> of the HTML file like various flex properties, box-shadow, color, etc. that give beautiful effects.Get the element from the id using the getElementById() method and store it in a variable similarly get the element paragraph and store it in another variable. Then use an addEventListener of type change and specify the function that is executed.Using the if condition check if the checkbox is checked then simply strike through the paragraph text and if the checkbox is unchecked then simply remove the strikethrough. Example: This example describes the basic implementation of the striking through a particular paragraph text with a checkbox. HTML <!DOCTYPE html> <html> <head> <title>Strike through Text</title> <style> #checkbox:checked, p#textToStrike { text-decoration: line-through; } body { display: flex; justify-content: center; align-items: center; height: 100vh; flex-direction: column; } #heading { color: green; } .main { border: 2px solid green; padding: 40px; box-shadow: 0px 4.5px 5.5px rgba(0, 0, 0, 0.15); border-radius: 15px; text-align: center; } </style> </head> <body> <h2 id=heading> GeeksforGeeks </h2> <div class="main"> <label for="checkbox"> <input type="checkbox" id="checkbox"> Scratch Text </label> <p id="TextToStrike"> Let's strike this text for fun. </p> </div> <script> const checkbox = document.getElementById("checkbox"); const textToCross = document.getElementById("TextToStrike"); checkbox.addEventListener("change", function () { // If checked, strike through // the paragraph text if (this.checked) { textToCross.style.textDecoration = "line-through"; } // If unchecked, remove the strikethrough else { textToCross.style.textDecoration = "none"; } }); </script> </body> </html> Output: Comment More infoAdvertise with us Next Article Create a Custom Checkbox using HTML CSS and JavaScript P pankaj_gupta_gfg Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Properties Similar Reads 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 Create a Custom Checkbox using HTML CSS and JavaScript This article will show you how to create a custom checkbox using HTML, CSS, and JavaScript that enables users to check on checkboxes along with the " Select all " feature. We have written a code that generates a card in the center of the window. The card displays a list of items along with checkboxe 4 min read How to Change the Checked Mark Color of a Checkbox using CSS? Checkboxes are commonly used on websites to enable users to make selections, such as agreeing to terms and conditions or choosing preferences. A checkbox is a small square box in forms that users can click to select or deselect an option. By default, the checkmark inside the checkbox has a basic sty 5 min read How to style label associated with selected radio input and checked checkboxes using CSS ? The HTML <input type=âradioâ> is used to define a Radio Button. Radio Buttons are used to let the user select exactly one option from a list of predefined options. Radio Button input controls are created by using the âinputâ element with a type attribute having value as âradioâ.In this article 2 min read How to Check/Uncheck the checkbox using JavaScript ? To check and uncheck the checkbox using JavaScript we can use the onclick event to toggle the checkbox value. We can also check or uncheck all the checkboxes on loading the webpage using JavaScript onload function.In this article, we will learn how to check/uncheck the checkbox using JavaScript. As 3 min read How to Make a Toggle Button using Checkbox and CSS ? Toggle means switching actions from one state to another. In simple words, when we switch from one state to the other state and back again to the former state we say that we are toggling. In this article, we are using the checkbox and CSS to create a toggle button. In web development, we can use thi 3 min read Like