How to change the strike-out / line-through thickness in CSS?
Solution 1:
The modern solution is to use the text-decoration-thickness property.
text-decoration-thickness: 1px;
You can also change the color using the text-decoration-color property.
text-decoration-color: #ff0000aa;
For older browsers, you can use one of these workarounds:
Here's a pure CSS method that doesn't require any unnecessary wrapper elements. As an added bonus, not only can you adjust the thickness of the strikeout, but you can control its color separately from the text color:
.strikeout {
font-size: 4em;
line-height: 1em;
position: relative;
}
.strikeout::after {
border-bottom: 0.125em solid red;
content: "";
left: 0;
margin-top: calc(0.125em / 2 * -1);
position: absolute;
right: 0;
top: 50%;
}
<span class="strikeout">Struck out text</span>
Use RGBa colors to make the strikeout semi-transparent:
.strikeout {
font-size: 4em;
position: relative;
}
.strikeout::after {
border-bottom: 0.125em solid rgba(255, 0, 0, 0.5);
content: "";
left: 0;
line-height: 1em;
margin-top: calc(0.125em / 2 * -1);
position: absolute;
right: 0;
top: 50%;
}
<span class="strikeout">Struck out text</span>
Or even make the strikeout a gradient! Just use a background
combined with a height
, in place of a border
:
.strikeout {
font-size: 4em;
line-height: 1em;
position: relative;
}
.strikeout::after {
background: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 0, 0, 1), rgba(0, 255, 0, 1), rgba(0, 0, 255, 1), rgba(255, 255, 255, 0));
content: "";
height: 0.125em;
left: 0;
margin-top: calc(0.125em / 2 * -1);
position: absolute;
right: 0;
top: 50%;
}
<span class="strikeout">Struck out text</span>
This works in IE9 (sans gradient) and up – or even IE8 if you use the single-colon :after
syntax and manually write the negative margin-top
value instead of using calc()
.
The main downside is that this only works on a single line of text. But hey, you take what you can get ;-)
Solution 2:
This seems to be a longstanding question without an ideal solution for multi-line strikethroughs.
Conveniently, using CSS gradients, you can easily adjust your line thickness like so:
strike {
text-decoration: none;
background-image: linear-gradient(transparent 7px,#cc1f1f 7px,#cc1f1f 9px,transparent 9px);
}
See the demo and full vendor prefixing here: http://codepen.io/pearlchen/pen/dhpxu
Solution 3:
short answer: no. it depends on the font, it's the same for the thickness of underline—it changes with the thickness of the text