CSS Highlight Text

12/17/2020

Contents

Demo

Full Screen

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 Highlight Text</title>
    <link rel="stylesheet" type="text/css" href="style.css">
  </head>
  <body>
    <div id="container">
      <h1>CSS <mark>Highlight Text</mark></h1>
    </div>
  </body>
</html>

CSS

@charset "utf-8";
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@700&display=swap');
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  font-size: 16px;
}
body {
  font-family: 'Roboto', sans-serif;
}
#container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100vh;
  background-color: #000;
}
h1 {
  color: #fff;
  font-size: 3rem;
  letter-spacing: 2px;
}
mark {
  padding: 4px 10px;
  background-image: linear-gradient(110deg, #405de6, #f32626, #ffdc80);
  color: #fff;
}
@media screen and (max-width: 480px) {
  h1 {
    font-size: 1.5rem;
  }
  mark {
    padding: 2px 4px;
  }
}