Gradient Background Color with HTML & CSS

12/17/2020

Contents

Demo

Full Screen

Code

HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Gradient Background Color</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="gradient-bg"></div>
      <h1>Gradient Background Color</h1>
    </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;
  position: relative;
  width: 100%;
  height: 100vh;
}
.gradient-bg {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 0;
  background-image: linear-gradient(135deg, #e62c85, #ebd836);
}
h1 {
  z-index: 1;
  width: 100%;
  margin: 0;
  padding: 20px 0;
  background-color: rgba(0, 0, 0, .5);
  color: #fff;
  font-weight: 600;
  font-size: 2.75rem;
  letter-spacing: 1px;
  text-align: center;
}
@media screen and (max-width: 480px) {
  h1 {
    font-size: 1.25rem;
  }
}