Gradient Underlines

a {
  position: relative;
  padding-bottom: 2px;
  text-decoration: none;
}

a:hover::after {
  content: "";
  position: absolute;
  bottom: 2px;
  left: 0;
  height: 1px;
  width: 100%;
  background: #444;
  background: linear-gradient(left, transparent 0%,#444 50%,transparent 100%);
 }

See the Pen Gradient Underlines by Chris Coyier (@chriscoyier) on CodePen.

Comments

  1. User Avatar
    asd
    Permalink to comment#

    yohooo

  2. User Avatar
    Nicklas
    Permalink to comment#

    Not bad!

    Throw some transition into that and it’ll be even fancy-er! :)

  3. User Avatar
    Sarang
    Permalink to comment#

    Awesome Man ! Thanx Big Thanx !

  4. User Avatar
    Brett M
    Permalink to comment#

    Is there a fix for line wrapping? When my link is long enough to wrap onto the next line, the next line won’t be underlined.

  5. User Avatar
    Shachar
    Permalink to comment#

    For Firefox needs -moz-linear-gradient(left, transparent 0%,#444 50%,transparent 100%);

  6. User Avatar
    rahul
    Permalink to comment#

    not bad.but it is only work in chrome.

  7. User Avatar
    Darma
    Permalink to comment#

    Hi, cool trick. You can make it work on other browser by adding vendor specific properties:

    background: -webkit-linear-gradient(left, transparent 0%,#444 50%,transparent 100%);
    background: -moz-linear-gradient(left, transparent 0%,#444 50%,transparent 100%);
    background: -o-linear-gradient(left, transparent 0%,#444 50%,transparent 100%);
    background: linear-gradient(left, transparent 0%,#444 50%,transparent 100%);

  8. User Avatar
    Mystic
    Permalink to comment#

    Nice trick !!

Submit a Comment

Posting Code

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.

icon-closeicon-emailicon-linkicon-logo-staricon-menuicon-nav-guideicon-searchicon-staricon-tag