The hero section of your website is the first thing visitors see, and it should leave a lasting impression. In this tutorial, we'll guide you through the process of creating a visually stunning hero section using HTML and CSS. Elevate your web design skills and make your website more engaging with this essential design element.
Step 1: HTML Markup:
Start by setting up the HTML structure for your hero section, creating a container for the hero content.
<!-- -------------------- HTML -------------------- -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- google font link -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link
href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&family=Open+Sans:ital,wght@0,300..800;1,300..800&display=swap"
rel="stylesheet">
<!-- CSS link -->
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="responsive.css">
</head>
<body>
<section>
<nav>
<div class="logo"><img src="logo.png" alt=""> Rayen</div>
<div class="menu-icon">|||</div>
<div class="menu-list js-menu-hide">
<ul class="link">
<li><a href="#">Home</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
<div class="sign">
<a href="#" class="login">Login</a>
<a href="#" class="sign-up">Sign Up</a>
</div>
</div>
</nav>
<main>
<div class="text-area">
<p class="desc">Introducing new technology</p>
<h1 class="heading">Easy <span>Design</span> <br><span>Easy</span> Website</h1>
<p class="tag-ling">User interface is very important these days.</p>
<div class="btns">
<button class="btn-sub">Subscribe</button>
<button class="btn-demo">Demo</button>
</div>
</div>
<div class="image-area">
<img src="OBJECTS.png" alt="">
</div>
</main>
</section>
<!-- java script link -->
<script src="main.js"></script>
</body>
</html>
Step 2: Styling with CSS:
Create a separate CSS file (style.css)
/*-------------------- CSS --------------------*/
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
min-height: 100vh;
}
:root {
--font-montserrat: "Montserrat", sans-serif;
--font-open-sans: "Open Sans", sans-serif;
}
a {
color: inherit;
text-decoration: none;
}
li {
list-style: none;
}
section {
position: relative;
min-height: 100vh;
background: linear-gradient(90deg, hsl(253, 48%, 31%), hsl(251, 90%, 20%));
overflow: hidden;
}
section::after,
section::before {
content: "";
position: absolute;
width: 20%;
aspect-ratio: 1;
pointer-events: none;
}
section::after {
top: 0;
left: 0;
background: linear-gradient(45deg, hsla(306, 41%, 41%, 0.7) 0%, hsla(306, 41%, 41%, 0.1) 40%, #fff0 50%);
rotate: 90deg;
}
section::before {
bottom: 0;
right: 0;
background: linear-gradient(45deg, hsla(200, 66%, 43%, 0.7) 0%, hsla(200, 66%, 43%, 0.1) 40%, #fff0 50%);
rotate: -90deg;
}
nav {
position: relative;
width: 90%;
margin: auto;
max-width: 1400px;
display: flex;
justify-content: space-between;
align-items: center;
padding-top: 50px;
}
nav .logo {
display: flex;
align-items: center;
cursor: pointer;
gap: 8px;
}
nav .logo img {
rotate: 0;
transition: 0.1s;
}
nav .logo:hover img {
rotate: 360deg;
}
nav .logo {
font-family: var(--font-open-sans);
font-weight: bold;
color: white;
font-size: 1.5rem;
letter-spacing: -0.1rem;
text-transform: uppercase;
}
nav .menu-icon {
color: white;
position: relative;
z-index: 10;
right: 5%;
letter-spacing: 1px;
rotate: 90deg;
font-size: 1.5rem;
cursor: pointer;
display: none;
}
nav .menu-list {
display: flex;
align-items: center;
gap: 40px;
}
nav .link {
display: flex;
gap: 30px;
font-family: var(--font-montserrat);
color: hsl(240, 77%, 72%);
}
nav .link li:hover a {
color: white;
}
nav .sign {
display: flex;
align-items: center;
gap: 20px;
font-family: var(--font-montserrat);
color: hsl(240, 77%, 72%);
}
nav .sign .login {
transition: 0.2s;
}
nav .sign .login:hover {
color: white;
}
nav .sign .sign-up {
color: white;
background: hsl(253, 100%, 68%);
padding: 10px;
border-radius: 7px;
border: 1px solid hsl(253, 100%, 68%);
font-weight: 600;
}
nav .sign .sign-up:hover {
background: transparent;
}
main {
width: 90%;
max-width: 1400px;
margin: auto;
display: flex;
justify-content: space-between;
}
main .text-area {
position: relative;
width: 40%;
padding: 100px 0;
display: flex;
flex-direction: column;
justify-content: center;
z-index: 3;
}
main .text-area .desc {
color: hsl(240, 71%, 89%);
font-family: var(--font-montserrat);
}
main .text-area .heading {
color: white;
font-family: var(--font-open-sans);
font-size: 4rem;
line-height: 4.2rem;
white-space: nowrap;
}
main .text-area .heading span:first-child {
color: hsl(42, 100%, 55%);
}
main .text-area .heading span:last-child {
color: hsl(240, 77%, 72%);
}
main .text-area .tag-ling {
margin-top: 20px;
color: hsl(240, 77%, 72%);
font-family: var(--font-montserrat);
}
main .text-area .btns {
margin-top: 40px;
display: flex;
gap: 30px;
}
main .text-area .btns button {
padding: 10px;
border-radius: 7px;
border: 1px solid hsl(253, 100%, 68%);
color: white;
font-weight: bold;
cursor: pointer;
}
main .text-area .btns .btn-sub {
background: hsl(253, 100%, 68%);
}
main .text-area .btns .btn-sub:hover {
background: transparent;
}
main .text-area .btns .btn-demo {
background: transparent;
}
main .text-area .btns .btn-demo:hover {
background: hsl(253, 100%, 68%);
}
main .image-area {
position: relative;
width: 50%;
padding: 100px 0;
display: flex;
flex-direction: column;
justify-content: center;
}
main .image-area img {
width: 110%;
max-height: 70vh;
object-fit: contain;
}
Step 3: Responsive Styling with CSS:
Create a separate CSS file (responsive.css)
/*-------------------- CSS --------------------*/
@media only screen and (max-width: 850px) {
nav {
width: 100%;
padding-left: 5% ;
}
nav .menu-icon {
display: block;
font-family: var(--font-montserrat);
}
nav .menu-list {
position: absolute;
top: 0;
right: 0%;
flex-direction: column;
padding: 80px 0;
height: 100vh;
min-width: 300px;
width: 40%;
background: hsla(0, 0%, 31%, 0.7);
backdrop-filter: blur(7px);
z-index: 5;
transition: 0.5s;
}
nav .menu-list .link {
color: white;
flex-direction: column;
align-items: center;
}
nav .menu-list .sign {
color: white;
flex-direction: column;
align-items: center;
}
.js-menu-hide {
transform: translateX(100%);
}
main .text-area .heading {
font-size: 3rem;
line-height: 3rem;
}
}
@media only screen and (max-width: 640px) {
nav {
padding-left: 10%;
padding-top: 20px;
}
main {
width: 80%;
flex-direction: column;
}
main .text-area {
order: 2;
width: 100%;
padding: 0;
}
main .image-area {
width: 100%;
padding: 0;
margin-top: 50px;
margin-bottom: 10px;
}
main .image-area img {
width: 70%;
margin: 0 auto;
}
}
@media only screen and (max-width: 400px) {
main .text-area .heading {
font-size: 2.3rem;
line-height: 2.3rem;
}
}
Step 3: Adding JavaScript Interaction:
Create a JavaScript
//-------------------- Java Script --------------------//
let minuIcon = document.querySelector(".menu-icon")
let minuMenu = document.querySelector(".menu-list")
minuIcon.addEventListener("click", ()=>{
if(minuMenu.classList.contains("js-menu-hide")) {
minuIcon.innerText = "X"
minuMenu.classList.remove("js-menu-hide")
}else {
minuIcon.innerText = "|||"
minuMenu.classList.add("js-menu-hide")
}
})
Customize your hero section by modifying the text, background image, colors, and styling to match your website's theme. This design element sets the stage for an impactful user experience.
0 Comments