Image Text Overlay

CSSCSSBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

In this lab, we will be learning about image text overlays using CSS. The purpose of this lab is to teach you how to display text on top of an image with an overlay, making it readable regardless of the background image and color. You will learn how to use the backdrop-filter property to apply a blur and brightness effect to your text, creating a professional and visually appealing design.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL css(("`CSS`")) -.-> css/BasicConceptsGroup(["`Basic Concepts`"]) css(("`CSS`")) -.-> css/BasicStylingGroup(["`Basic Styling`"]) css(("`CSS`")) -.-> css/CoreLayoutGroup(["`Core Layout`"]) css/BasicConceptsGroup -.-> css/selectors("`Selectors`") css/BasicStylingGroup -.-> css/fonts("`Fonts`") css/BasicStylingGroup -.-> css/text_styling("`Text Styling`") css/CoreLayoutGroup -.-> css/margin_and_padding("`Margin and Padding`") css/CoreLayoutGroup -.-> css/positioning("`Positioning`") subgraph Lab Skills css/selectors -.-> lab-35247{{"`Image Text Overlay`"}} css/fonts -.-> lab-35247{{"`Image Text Overlay`"}} css/text_styling -.-> lab-35247{{"`Image Text Overlay`"}} css/margin_and_padding -.-> lab-35247{{"`Image Text Overlay`"}} css/positioning -.-> lab-35247{{"`Image Text Overlay`"}} end

Image Text Overlay

index.html and style.css have already been provided in the VM.

To display text on top of an image with an overlay, use the backdrop-filter property to apply a blur(14px) and brightness(80%) effect. This ensures that the text is readable regardless of the background image and color. Here is an example HTML code:

<div>
  <h3 class="text-overlay">Hello, World</h3>
  <img src="https://picsum.photos/id/1050/1200/800" />
</div>

And the corresponding CSS code:

div {
  position: relative;
}

.text-overlay {
  position: absolute;
  top: 0;
  left: 0;
  padding: 1rem;
  font-size: 2rem;
  font-weight: 300;
  color: white;
  backdrop-filter: blur(14px) brightness(80%);
}

Please click on 'Go Live' in the bottom right corner to run the web service on port 8080. Then, you can refresh the Web 8080 Tab to preview the web page.

Summary

Congratulations! You have completed the Image Text Overlay lab. You can practice more labs in LabEx to improve your skills.

Other CSS Tutorials you may like