Text that shows an underline on hover

HtmlCss

Html Problem Overview


Can you underline a text on hover using css? (Like the behavior of a link but not an actual link.)

  1. you have the following text Hello work
  2. when you hover your mouse over the text it underlines it using css

(the text is not a link)

Html Solutions


Solution 1 - Html

<span class="txt">Some Text</span>

.txt:hover {
    text-decoration: underline;
}

Solution 2 - Html

You just need to specify text-decoration: underline; with pseudo-class :hover.

HTML

<span class="underline-on-hover">Hello world</span>

CSS

.underline-on-hover:hover {
	text-decoration: underline;
}

I have whipped up a working Code Pen Demo.

Solution 3 - Html

Fairly simple process I am using SCSS obviously but you don't have to as it's just CSS in the end!

HTML

<span class="menu">Menu</span>

SCSS

.menu {
    position: relative;
    text-decoration: none;
    font-weight: 400;
    color: blue;
    transition: all .35s ease;

    &::before {
        content: ""; 
        position: absolute;
        width: 100%;
        height: 2px;
        bottom: 0;
        left: 0;
        background-color: yellow;
        visibility: hidden;
        -webkit-transform: scaleX(0);
        transform: scaleX(0);
        -webkit-transition: all 0.3s ease-in-out 0s; 
        transition: all 0.3s ease-in-out 0s; 
    }   

    &:hover {
        color: yellow;

        &::before {
            visibility: visible;
            -webkit-transform: scaleX(1);
            transform: scaleX(1);
        }   
    }   
}

Solution 4 - Html

li {
 display:inline-block;
 padding:15px;
}

li:hover {
  color: Blue;
  border-bottom: 3px solid Blue;
}

<ul>
  <li>Hello work</li>
 </ul>

Solution 5 - Html

.resume_link:hover{
  text-decoration: underline;
  text-decoration-color: rgb(250, 114, 64);
  -moz-text-decoration-color: rgb(250, 114, 64);
  text-decoration-thickness: 5px;
}

<a class="resume_link">Resume</a>

Solution 6 - Html

<span class="text">Click Me</span>

.text:hover {
    text-decoration: underline black //This colour is an example
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLacerView Question on Stackoverflow
Solution 1 - HtmleffoneView Answer on Stackoverflow
Solution 2 - HtmlryanwinchesterView Answer on Stackoverflow
Solution 3 - HtmlJohn DownsView Answer on Stackoverflow
Solution 4 - HtmlPriyanka VadhwaniView Answer on Stackoverflow
Solution 5 - HtmlAgatha AmbroseView Answer on Stackoverflow
Solution 6 - HtmlRaLeView Answer on Stackoverflow