Strikethrough text in HTML is very common and you might have come across its implementation on e-commerce platforms where the original price is strikethrough and the discounted price is listed. Another, usage of strikethrough text is common in documents where the difference is highlighted between old and new text while comparing document revisions.
Similar to word documents, text inside HTML elements can be strikethrough using a couple of different ways described below.
<del>
HTML5 introduced <del>
semantic element which can be used to highlight the portion of text that was deleted. <del>
element can be used with <ins>
to highlight new text that has been inserted in the document. Let’s see its application in the following example:
<h3>Published in <del>2019</del> <ins>2020</ins>.</h3>
<s>
Semantic element <s>
functions similar to <del>
element however their is difference in the meaning that these tags convey. When text is not relevant to document anymore, we should be using <s>
element, and when text is deleted from the document we should be using the <del>
element.
<h3>Price <s>$49.99</s> <strong>$39.99</strong></h3>
text-decoration:line-through
Striking through in CSS can be achieved using the text-decoration
property.
When text-decoration: line-through
property is defined on text element, the horizontal line is placed over text.
.strike { text-decoration: line-through; text-decoration-color: red; }
<h3>Published in <span class="strike">2019</span> 2020.</h3>
<strike>
(Deprecated)<strike>
tag is obsolete and was deprecated in HTML5. The HTML <strike>
tag places a horizontal line over text.
Published in <strike>2019</strike> 2020.
The presence of the <del>
, <ins>
and <strike>
element is not announced by most screen reading technology in its default configuration. It can be made to be announced by using the CSS content property, along with the ::before
and ::after
pseudo-elements. Source MDN