<!-- --------------- Created By InCoder --------------- -->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Cookie Consent Box - InCoder</title>
    <link rel="stylesheet" href="main.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
</head>

<body>
    <div class="consent-box">
        <div class="icon">
            <i class="fas fa-cookie-bite"></i>
        </div>
        <div class="text">
            <p>We uses cookie to ensure you get the best experience on our website.</p>
        </div>
        <div class="action">
            <a href="#">Learn more</a>
            <button id="acceptConsent">Accept</button>
        </div>
    </div>
</body>

</html>
/* --------------- Created By InCoder --------------- */

@import url("https://fonts.googleapis.com/css2?family=Poppins&display=swap");

* {
  margin: 0;
  padding: 0;
  font-family: "Poppins", sans-serif;
}

body {
  background-color: #db2d2d;
}

.consent-box {
  left: 1rem;
  bottom: 2rem;
  width: 14rem;
  position: fixed;
  border-radius: 8px;
  padding: 1rem 1.5rem;
  background-color: #fff;
  box-shadow: 0px 0px 15px #ccc;
  transition: opacity 0.3s ease-in-out;
}

.consent-box .icon i {
  font-size: 6rem;
  color: #db2d2d;
  margin: auto 0 auto 0;
}

.consent-box .icon,
.consent-box .text,
.consent-box .action {
  display: flex;
  align-items: center;
  margin-bottom: 0.5rem;
  justify-content: center;
}

.consent-box .action {
  justify-content: space-between !important;
}

.consent-box .action a {
  color: #111;
  text-decoration: none;
}

.consent-box .action a:hover {
  color: #db2d2d;
  text-decoration: underline;
}

.consent-box .action button {
  border: 0px;
  padding: 5px 25px;
  border-radius: 5px;
  cursor: pointer;
  background-color: rgb(219 45 45 / 90%);
  color: #fff;
}

.consent-box .action button:hover {
  background-color: #db2d2d;
  color: #fff;
}

.consent-box.hide {
  opacity: 0;
  transition: 0.5s;
  transform: scale(0.9);
}
let consentBox = document.querySelector(".consent-box");
acceptButton = document.querySelector("#acceptConsent");

function getCookie(name) {
  const value = `; ${document.cookie}`;
  const parts = value.split(`; ${name}=`);
  if (parts.length === 2) return parts.pop().split(";").shift();
}

acceptButton.addEventListener("click", function () {
  document.cookie =
    "InCoder_Cookie=yes; expires=" + 60 * 60 * 24 * 30 + "; path=/";
  if (document.cookie) {
    consentBox.classList.add("hide");
  } else {
    alert(
      "Cookie can't be set! Please unblock this site from the cookie setting of your browser."
    );
  }
});

if (getCookie("InCoder_Cookie") != null) {
  consentBox.style.display = "none";
}
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.