Creating a Hero Section
A "hero section" is the large banner visually prominently displayed at the top of a webpage, usually immediately below the navigation bar. Creating one relies on striking CSS typography and substantial padding.
Because it's the first thing users see on a landing page, a hero section needs to instantly communicate what the site is about. It usually consists of a large headline, a brief explanatory subtitle, and one or two "Call to Action" (CTA) buttons.
Establishing the HTML Structure
To create a hero section, we often use the semantic header tag (though a generic div or section also works). Inside, we place our h1 headline, a paragraph for the subtext, and our buttons:
Styling the Hero Background and Text
Hero sections command attention through size and contrast. We achieve the height by applying massive padding. We achieve the contrast by applying a dark background (like a solid color, an image, or a gradient) and making the color of the text white:
Full Working Example
Below is a complete implementation of a hero section, including nicely styled "pill-shaped" buttons. If you resize your browser, you will notice a media query decreases the padding and font sizes on mobile devices so the text doesn't overflow the screen:
Tip: Full Screen Height Hero
If you want your hero section to take up exactly 100% of the user's screen height before they start scrolling, you can apply min-height: 100vh; (viewport heights) to the .hero CSS class!