
- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursors
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS Advanced
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Media Types
- CSS - Paged Media
- CSS - Aural Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS3 - Rounded Corner
- CSS3 - Border Images
- CSS3 - Multi Background
- CSS3 - Color
- CSS3 - Gradients
- CSS3 - Shadow
- CSS3 - Text
- CSS3 - Web font
- CSS3 - 2d transform
- CSS3 - 3d transform
- CSS3 - Animation
- CSS3 - Multi columns
- CSS3 - User Interface
- CSS3 - Box Sizing
- CSS Responsive
- CSS - Responsive Web Design
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
How to create a Hero Image with CSS?
Following is the code to create a hero image with CSS −
Example
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1" /> <style> body, html { height: 100%; margin: 0; font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } *, *::before, *::after { box-sizing: border-box; } h1 { font-size: 60px; font-weight: bolder; } .heroContainer { background-image: linear-gradient( rgba(185, 255, 243, 0.5), rgba(31, 12, 117, 0.5) ), url("https://images.pexels.com/photos/670720/pexels-photo-670720.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=1000"); height: 50%; background-position: center; background-repeat: no-repeat; background-size: cover; position: relative; } .heroCaption { text-align: center; position: absolute; top: 20%; left: 45%; color: white; } .heroCaption button { border: none; outline: none; display: inline-block; padding: 20px; color: rgb(255, 255, 255); opacity: 0.8; font-size: 20px; background-color: rgb(47, 151, 21); text-align: center; cursor: pointer; } .heroCaption button:hover { opacity: 1; } </style> </head> <body> <div class="heroContainer"> <div class="heroCaption"> <h1>I am Shawn</h1> <h2>And I'm a Web Developer</h2> <button>Contact Me</button> </div> </div> </body> </html>
Output
The above code will produce the following output −
- Related Articles
- How to create a responsive image with CSS?
- How to create a sticky image with CSS?
- How to create image filters with CSS
- How to create a responsive image gallery with CSS
- How to create a blurry background image with CSS?
- How to create an image gallery with CSS
- How to create an avatar image with CSS?
- How to create a "black and white" image with CSS?
- How to create a full-page background image with CSS?
- Create a transparent image with CSS
- Create a mirror image with CSS
- How to create a thumbnail image CSS?
- How to create image overlay hover effect with CSS?
- How to create a modal image gallery with CSS and JavaScript?
- How to create a responsive Image Grid with HTML and CSS?

Advertisements