Create Marketing Hero Section Using HTML and CSS
Create Marketing Hero Section Using HTML and CSS
Learn how to create a responsive marketing hero section using HTML and CSS.
Join us on Telegram
Read Also
Create Interactive Add/Remove Cards with HTML, CSS, and
JavaScript
Table of Contents
1. Project Introduction
2. HTML Code
3. CSS Code
4. Conclusion
5. Preview
A hero section is the first thing visitors see when they visit a website, and it's
important to make it stand out. It usually includes a bold headline, catchy text,
and a call-to-action (CTA) button. In this blog, you'll learn how to create a
marketing hero section using HTML and CSS. This guide is perfect for
beginners, and by the end, you'll have a simple, professional hero section for
your website.
Prerequisites:
Before you start, you should have a basic understanding of:
Source Code
Start by creating the basic HTML structure. This will include a container,
headline, text, and button inside your hero section.
`<!DOCTYPE html>`
`<html lang="en">`
`<head>`
Contains meta information and links to resources like fonts, stylesheets, and the
page's title.
`<body>`
The body contains all the visible content, including the navigation bar and the
hero section.
Contains the site logo, a menu, and actions (like login and "Get started"
buttons).
Logo: An image linked to the homepage (`logo.svg`).
Menu: A list of links such as "How it works," "Goals," etc.
Mobile menu: Includes buttons for opening/closing the menu with an icon
button using `svg` graphics.
Actions: Provides "Login" and "Get started" buttons.
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <meta name="viewport" content="width=device-width, initia
6 <title>Marketing Hero Section</title>
7 <link href="https://fonts.googleapis.com/css2?family=Robo
8 <link rel="stylesheet" href="styles.css">
9 </head>
10 <body>
11 <nav id="nav" class="nav">
12 <div class="nav-container">
13 <a href="#" class="logo-wrapper">
14 <img
15 class="logo-img"
16 src="https://raw.githubusercontent.com/mobalti/op
17 alt="Open Props logo"
18 width="160"
19 height="29.44"
20 />
21 </a>
22 <div class="menu-wrapper">
23 <div class="mobile-wrapper">
24 <div class="mobile-mobile-head">
25 <a href="#" class="logo-wrapper">
26 <img
27 class="logo-img"
28 src="https://raw.githubusercontent.com/moba
29 alt="Open Props logo"
30 width="160"
31 height="29.44"
32 />
Read Also
Create a Subscription Form with Personalized Messaging
Next, add CSS to style your hero section. Let's break it down into sections:
1. @import
@import 'https://unpkg.com/[email protected]' layer(library);
This imports a library called "Open Props," which provides a set of reusable
design tokens (CSS variables) for colors, spacing, typography, etc.
2. @layer reset
@layer reset {
*,:before,:after {
box-sizing: border-box;
}
:where(:not(dialog)) {
margin: 0;
}
}
3. @layer base
@layer base {
:root {
color-scheme: dark;
font-family: 'Inter', sans-serif;
--palette-hue: 249;
--red: #e81155;
--surface-1: black;
--surface-invert: white;
--text-1: white;
--highlight-text: var(--red);
--headline1-font-size: var(--font-size-fluid-3);
...
}
body {
background-color: var(--surface-1);
color: var(--text-1);
font-size: var(--body-font-size);
min-block-size: 100dvb;
}
}
The `:root` defines global variables (CSS custom properties) for colors, font
sizes, and spacing. These variables can be reused throughout the
document.
`color-scheme: dark` sets the default theme to dark mode.
Variables like `--palette-hue`, `--surface-1`, and `--highlight-text` control
the hue, background color, and highlight color, respectively.
The `body` styles set a black background and white text for the entire page.
5. Buttons
.button-link {
font-size: var(--button-link-font-size);
background-color: var(--button-link-face);
color: var(--button-link-text);
&:hover {
background-color: var(--button-link-hover-face);
}
&.primary {
background-color: var(--button-link-primary-face);
}
}
`.button-link` is a generic button style with custom properties for font size,
color, and hover effects.
The `.primary` class modifies the button with a primary background color
and custom hover behavior.
6. Animations
@keyframes animate-ratio {
from {
aspect-ratio: 16/9;
clip-path: inset(0 0);
}
to {
aspect-ratio: 2.5/6;
clip-path: inset(120px 0 50px 0);
}
}
@keyframes push-up {
10%, 90% {
transform: translateY(-100%);
}
100% {
transform: translateY(-200%);
}
}
7. Responsive Design
@media (width >= 700px) {
--headline1-font-size: var(--extend-font-size-fluid-4);
}
@media (width < 1056px) {
--nav-link-font-size: var(--font-size-3);
}
Media queries adjust font sizes, padding, and layout for different screen
widths. For example, the headline font size becomes larger on screens wider
than 700px, and the navigation link font size becomes larger on screens
smaller than 1056px.
Final Output:
Read Also