Blur background image in HTML and CSS


There are two ways to blur div background. First one is using img tag in HTML and second is using background-image in CSS. The first method is preferred as it doesn't blur the inner content of div. For better understanding, check the code below and see the example on the demo page.

Source Code:

<!--Example 1-->
<style>
	.blur-bg {
		position: relative;
	}
	.blur-bg .bg-image {
		filter: blur(3px);
		max-width: 100%;
	}
	.blur-bg .content {
		position: absolute;
		top: 0;
		left: 0;
		color: #fff;
		padding: 25px;
	}
</style>
<div class="blur-bg">
	<img class="bg-image" src="blur-background-image-in-html-and-css.jpg" alt="Blur background image in HTML and CSS"/>
	<div class="content">
		<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
	</div>
</div>

<!--Example 1-->
<style>
	.blur-bg-2 {
		background-image: url(blur-background-image-in-html-and-css.jpg);
		filter: blur(2px);
		padding: 66px 0;
	}
	.blur-bg-2 .content {
		color: #fff;
		padding: 25px;
	}
</style>
<div class="blur-bg-2">
	<div class="content">
		<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
	</div>
</div>

Free - Download it right now!


Tested

Include all files

Demo Download

Buy us coffee

Compatible Browsers

Chrome, Firefox, Safari, Opera, IE9+, Edge

Technologies Used

HTML 5, CSS 3

Reviews and Comments