# Display a featured image as a background image

**URL:** <https://community.hubspot.com/t/display-a-featured-image-as-a-background-image/983>\
**Category:** CMS Development\
**Created:** [February 15, 2017, 12:44am UTC](https://community.hubspot.com/t/display-a-featured-image-as-a-background-image/983 "2017-02-15T00:44:27Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![dbarbara](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dbarbara/32/10081_2.png) [@dbarbara](https://community.hubspot.com/u/dbarbara)\
**Post date:** [February 15, 2017, 12:44am UTC](https://community.hubspot.com/t/display-a-featured-image-as-a-background-image/983/1 "2017-02-15T00:44:27Z")

</div>

Am trying to get a featured image to show as a background image, and need to figure out the HubL to call a featured image from inside some HTML.

Thanks to @Jsum for part of the answer [here](https://community.hubspot.com/t5/COS-Design-Support/Is-there-a-way-to-allow-content-creator-to-alter-background/m-p/6037).

This is what I have so far, but not sure how to write 'background: url ’ so it calls the image.

```auto
{% for feature_item in featured_topic %}

{% image_src "image_src" %}

<div class="featured-post">
<div class="span6"> 

{% if feature_item.post_list_summary_featured_image %}

<span style='background: url ( {% image_src "{{ feature_item.post_list_summary_featured_image }}" %} ) center center no-repeat; background-size: cover;' class="hs-featured-image featured-post-image-1">

</span>
{% endif %}
</div>

```

---

<div class="post-metadata">

**Author:** ![dbarbara](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dbarbara/32/10081_2.png) [@dbarbara](https://community.hubspot.com/u/dbarbara)\
**Post date:** [February 15, 2017, 1:11am UTC](https://community.hubspot.com/t/display-a-featured-image-as-a-background-image/983/2 "2017-02-15T01:11:04Z")

</div>

Some progress! Have gotten the image URL to show up when looking at the source in dev tools, but it’s not displaying.

```auto
{% if feature_item.post_list_summary_featured_image %}				
<span style='background: url("{{ feature_item.post_list_summary_featured_image }}") center center no-repeat; background-size: cover;' class="hs-featured-image featured-post-image-1">					
</span>
{% endif %}

```

---

<div class="post-metadata">

**Author:** ![Jsum](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jsum/32/20405_2.png) [@Jsum](https://community.hubspot.com/u/Jsum)\
**Post date:** [February 15, 2017, 3:06am UTC](https://community.hubspot.com/t/display-a-featured-image-as-a-background-image/983/3 "2017-02-15T03:06:29Z")

</div>

You are using a span tag which is an inline element (like text). It can’t be styled like block elements. Do you have “display: block;” assigned to the span tag in your css? if not you can try that or use a div element instead of a span tag which is probably better syntax.

Also, regardless of element used, a height and a width need to be set other wise nothing is keeping it from being 0x0.

hopefully ones of these helps. Also quotations within the url value of the background attribute are not required. Using them shouldn’t have anything to do with your issue, and your code doesn’t appear to have any errors. The below just has the quotation marks adjusted.

```auto
{% if feature_item.post_list_summary_featured_image %}				
<span style="background: url({{ feature_item.post_list_summary_featured_image }}) center center no-repeat; background-size: cover;"class="hs-featured-image featured-post-image-1">					
</span>
{% endif %}

```

---

<div class="post-metadata">

**Author:** ![dbarbara](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dbarbara/32/10081_2.png) [@dbarbara](https://community.hubspot.com/u/dbarbara)\
**Post date:** [February 15, 2017, 5:24pm UTC](https://community.hubspot.com/t/display-a-featured-image-as-a-background-image/983/4 "2017-02-15T17:24:53Z")

</div>

Thanks for the input on the code.

I did realize that the image wasn’t displaying because there was no content inside \<span\>\</span\> When I added “display: block” as well as a min-height and “width: 100%” everything worked fine.

What’s built now is a nice card layout with an image on the left that adjusts based on the viewport width (vs. just reducing both width and height). It can be seen here: [http://cloudburst.astadia.com/blog](http://cloudburst.astadia.com/blog)

---

<div class="post-metadata">

**Author:** ![Jsum](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jsum/32/20405_2.png) [@Jsum](https://community.hubspot.com/u/Jsum)\
**Post date:** [February 15, 2017, 5:27pm UTC](https://community.hubspot.com/t/display-a-featured-image-as-a-background-image/983/5 "2017-02-15T17:27:37Z")

</div>

@dbarbara that looks great!

---

<div class="post-metadata">

**Author:** ![martin3walker](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/martin3walker/32/78108_2.png) [@martin3walker](https://community.hubspot.com/u/martin3walker)\
**Post date:** [October 31, 2017, 5:47pm UTC](https://community.hubspot.com/t/display-a-featured-image-as-a-background-image/983/6 "2017-10-31T17:47:48Z")

</div>

I want to use the featured image of my latest posts for as the background for a hero banner for my blog. I put a hubl module over the listing template.

 ![Screen Shot 2017-10-31 at 6.42.20 PM.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/f/f59725099fec9eb13259a4700111bd78af63cf8b.png)  
HubL Module

And, I’m trying to use the following code within that module to display the featured image from the lastest post.

```auto
{% for post in posts %}
 {% if loop.index = 1 %}

 <div class=blog-hero style="background:url('{{ content.featured_image }}') top center no-repeat; background-size: cover;"></div>

 {% endif %}
{% endfor %}

```

Any idea where I’m going wrong?

---

<div class="post-metadata">

**Author:** ![Jsum](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jsum/32/20405_2.png) [@Jsum](https://community.hubspot.com/u/Jsum)\
**Post date:** [November 9, 2017, 4:17pm UTC](https://community.hubspot.com/t/display-a-featured-image-as-a-background-image/983/7 "2017-11-09T16:17:43Z")

</div>

Your looping for post in posts but your targeting content.featured\_image. It shouldbe post.featured\_image

---

<div class="post-metadata">

**Author:** ![martin3walker](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/martin3walker/32/78108_2.png) [@martin3walker](https://community.hubspot.com/u/martin3walker)\
**Post date:** [November 13, 2017, 5:45pm UTC](https://community.hubspot.com/t/display-a-featured-image-as-a-background-image/983/8 "2017-11-13T17:45:15Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/system/32/124_2.png) [@system](https://community.hubspot.com/u/system)\
**Post date:** [June 14, 2020, 5:52pm UTC](https://community.hubspot.com/t/display-a-featured-image-as-a-background-image/983/9 "2020-06-14T17:52:44Z")

</div>

Can someone post an update on how to do this under the new CMS theme structure? Set feature Image as Blog Post header/banner background image.

---

<div class="post-metadata">

**Author:** ![JessicaH](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jessicah/32/14826_2.png) [@JessicaH](https://community.hubspot.com/u/JessicaH)\
**Post date:** [June 15, 2020, 8:08am UTC](https://community.hubspot.com/t/display-a-featured-image-as-a-background-image/983/10 "2020-06-15T08:08:10Z")

</div>

Hi @Anonymous,

Thanks for reaching out.

@Jsum would you be able to assist with this?

Thanks!

Jess
