Designing a Sleek Glass-Looking Hero Section with HTML and CSS


The hero section of a website is where you make your first impression. In this tutorial, we'll walk you through creating a stunning glass-like hero section using HTML and CSS. Elevate your web design skills and craft a captivating entry point for your website with this elegant design element.




Step 1: HTML Markup:

Begin by setting up the HTML structure for your glassy hero section, defining the container and its content.
<!-- -------------------- HTML -------------------- -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Hero Page</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css">

    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="glass">
        <div class="navbar">
            <div class="logo">
                <a href="#"><img src="logo.svg" alt=""></a>
            </div>
            <ul>
                <li><a href="#">Home</a></li>
                <li><a href="#">About</a></li>
                <li><a href="#">Code</a></li>
                <div class="form">
                    <input type="search" value="">
                    <button class="btn"><i class="bi bi-search"></i></button>
                </div>
            </ul>
        </div>
        <span>GLASS</span>
        <div class="icons">
            <i class="bi bi-facebook"></i>
            <i class="bi bi-instagram"></i>
            <i class="bi bi-twitter"></i>
        </div>
    </div>

    
</body>
</html>

Step 2: Styling with CSS:

Create a separate CSS file (style.css)
/*-------------------- CSS --------------------*/
@import url("https://fonts.googleapis.com/css?family=Rajdhani:300&display=swap");

*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: sans-serif;
}
body{
    min-height: 100vh;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background: url(img\ \(3\).jpg);
    background-size: cover;
    background-position: center;
}

.glass{
    position: relative;
    width: 70%;
    height: 70vh;
    background: linear-gradient(#fff2, #fff0);
    border: 1px solid #fff2;
    backdrop-filter: blur(10px);
    border-radius: 20px;
    box-shadow: 12px 12px 25px #0004;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

span{
    position: absolute;
    z-index: 5;
    color: white;
    font-size: 5rem;
    letter-spacing: 1.9rem;
    font-family: "Rajdhani", sans-serif;
}

.navbar{
    position: absolute;
    width: 100%;
    height: 60px;
    top: 0;
    left: 0;
    box-shadow: 5px 5px 12px #0004;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.logo{
    height: 40px;
}
.logo img{
    height: 100%;
}
ul{
    display: flex;
    margin: 0;
    align-items: center;
}
ul li{
    list-style: none;
}
ul li a{
    font-size: 1.2rem;
    color: white;
    margin: 0 10px;
    transition: 0.5s;
    top: 0;
    position: relative;
}
ul li:hover a{
    color: #424242;
    top: -3px;
    text-decoration: none;
}

.form input{
    outline: none;
    border: 0;
    border-radius: 10px;
    padding: 8px 35px 8px 15px;
    width: 200px;
}
.form .btn{
    color: black;
    position: relative;
    right: 30px;
    background: transparent;
    border: 0;
    cursor: pointer;
}


.icons{
position: absolute;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
}

.icons i{
    background: transparent;
    padding: 3px;
    color: white;
    border-radius: 5px;
    box-shadow: inset 1px 1px 1px #b9b9b9;
    margin: 0 7px;
    transition: 0.5s;
    cursor: pointer;
    position: relative;
    top: 0;
}
.icons i:hover{
    box-shadow: inset 0px 0px 0px #b9b9b9;
    top: -4px;
}

Customize your glassy hero section by modifying colors, text, and background images to match your website's style. This elegant design element will provide an attractive entry point for your website.

0 Comments