Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 2495

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 26, 20242024-11-26T05:55:07+00:00 2024-11-26T05:55:07+00:00

Mastering Background Image Darkening with CSS: Simple Yet Effective Techniques

  • 61k

Upon scrolling through amazing landing page designs on Behance I found myself googling how to darken background images with CSS because I wanted to build a page like the one below.
A landing page with darkened background image
I went through a few posts on Stack overflow and the answers were so overwhelming. I then decided to ask ChatGPT how I would darken my background image with CSS. The answers Stack Overflow suggested were not so different from what ChatGPT's answers. Both suggested I use an overlay then apply the background-color property to the overlay and set it to rgba(0,0,0,0.7). They also suggested I use the filter property which ended up reducing the brightness of the text on the page too. Another suggestion was that I use before or after pseudo-elements.

Image description

As a beginner who is not so comfortable with these concepts, I decided to read on the various background image and background color properties on Mozilla Developer Network and found the two-line secret to darkening background images.

But before that let's go through using the various concepts suggested by ChatGPT and Stack overflow to darken our background image.
Throughout this article this the HTML codes we will be using

<!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <title>Document</title>     <link rel="stylesheet" href="style.css"> </head> <body>     <main>         <div class="text">Lorem ipsum dolor sit amet consectetur adipisicing elit. Ullam, laudantium.</div>     </main> </body> </html> 
Enter fullscreen mode Exit fullscreen mode

A few CSS Styling to make our work look nice

body{     padding: 0;     margin: 0;     box-sizing: border-box; } main{     width: 100vw;     height: 100vh;     background-image: url("./img/workspace-gdfb557ae9_1280.jpg");     background-position: center;     background-repeat: no-repeat;     background-size: cover;     display: flex;     justify-content: center;     align-items: center; } main .text{     color: #fff;     font-size: xx-large; } 
Enter fullscreen mode Exit fullscreen mode

This the link to the background image we will be using in this article here

1. Using the FILTER CSS Property

Let's add this piece of code to our CSS styling we have above.

main{     filter: brightness(50%);     -webkit-filter: brightness(50%); } 
Enter fullscreen mode Exit fullscreen mode

The result after applying the filter CSS property

This is one of the easiest techniques of darkening your background image. The only disadvantage to this technique is that it reduces the legibility of the text on your page.

2. Using the ::before pseudo-elements

main{     position: relative; } main::before{     content: "";     width:100vw;     height: 100vh;     background-color: rgba(0, 0, 0, 0.7);     position: absolute; } main .text{     position: relative;     z-index: 20; } 
Enter fullscreen mode Exit fullscreen mode

The result after using the ::before pseudo-element

For just darkening your background image while making sure the texts on the page are legible, this just too much from my point of view and probably every beginner's point of view. It contains so many concepts that may be difficult for beginners to grasp.

3. Using the background-blend-mode CSS Property

main{     background-color: rgba(0, 0, 0, 0.7);     background-blend-mode: darken;  } 
Enter fullscreen mode Exit fullscreen mode

This the simplest and the most effective way of darkening your background image while making sure your texts on your page are legible.

Conclusion

There are several methods to darken a background image using CSS, but the most effective and beginner-friendly approach is by using the background-blend-mode property with the value of darken. This method allows you to darken the background image without affecting the text's legibility on the page.

Here's the final CSS code using the background-blend-mode property:

main {   width: 100vw;   height: 100vh;   background-image: url("./img/workspace-gdfb557ae9_1280.jpg");   background-position: center;   background-repeat: no-repeat;   background-size: cover;   display: flex;   justify-content: center;   align-items: center;   background-color: rgba(0, 0, 0, 0.7);   background-blend-mode: darken; } main .text {   color: #fff;   font-size: xx-large; } 
Enter fullscreen mode Exit fullscreen mode

beginnerscsshtmlwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    ES6 - A beginners guide - Template Literals

    • 0 Answers
  • Author

    Understanding Higher Order Functions in JavaScript.

    • 0 Answers
  • Author

    Build a custom video chat app with Daily and Vue.js

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.