How to Create CSS Custom Text Underline

Web Design & Web Development

Demo

Sponsored links

 

Video

YouTube Channel

 

Code

HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>CSS Custom Text Underline</title>
    <link rel="stylesheet" type="text/css" href="https://demo.plantpot.works/assets/css/normalize.css">
    <link rel="stylesheet" href="https://use.typekit.net/opg3wle.css">
    <link rel="stylesheet" type="text/css" href="style.css">
  </head>
  <body>
    <div id="container">
      <div class="text">
        <p class="underline-01">Text Underline</p>
        <p class="underline-02">Text Underline</p>
        <p class="underline-03">Text Underline</p>
        <p class="underline-04">Text Underline</p>
        <p class="underline-05">Text Underline</p>
        <p class="underline-06">Text Underline</p>
      </div>
    </div>
  </body>
</html>

CSS

@charset "utf-8";
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  font-size: 16px;
}
body {
  font-family: futura-pt, sans-serif;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
}
#container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100vh;
  padding: 20px;
}
.text p {
  margin: 10px 0 10px;
  color: #413832;
  font-size: 2.5rem;
  text-align: center;
}
/* solid underline */
.underline-01 {
  -webkit-text-decoration: underline solid #413832;
  text-decoration: underline solid #413832;
}
/* double underline */
.underline-02 {
  -webkit-text-decoration: underline double #b373B3;
  text-decoration: underline double #b373B3;
}
/* dotted underline */
.underline-03 {
  -webkit-text-decoration: underline dotted #59bfb3;
  text-decoration: underline dotted #59bfb3;
}
/* dashed underline */
.underline-04 {
  -webkit-text-decoration: underline dashed #f2a640;
  text-decoration: underline dashed #f2a640;
}
/* wavy underline */
.underline-05 {
  -webkit-text-decoration: underline wavy #22a4be;
  text-decoration: underline wavy #22a4be;
}
/* gradient underline */
.underline-06 {
  background-image: linear-gradient(90deg, #e67399, #f2a640);
  background-position: bottom;
  background-size: 100% 30%;
  background-repeat: no-repeat;
}
@media screen and (max-width: 480px) {
  #container {
    height: auto;
    align-items: flex-start;
  }
  .text p {
    font-size: 2rem;
  }
}