1

I've got a component on which I need to show an image:

import React from 'react'
import background from '../media/content-background.jpg'

function ContentPage(){
    return(
        <div id="content-page">
            <div id="content-header">
                <img href={background} alt='back'/>
            </div>
            <div id="content-body">

            </div>
        </div>
    )
}

export default ContentPage

The image is generated correctly as when I go to the url as specified in the inspector, it shows up in the browser.

enter image description here

But on the webpage only the alt is shown:

enter image description here

3 Answers 3

2

You should use src="" instead of href="".

href is used for specifying where you want a link to go, such as in an tag.

Sign up to request clarification or add additional context in comments.

Comments

1

The problem is that you are using the wrong attribute in your img tag, use src instead:

<img src={background} alt='back'/>

Comments

1

Change href to src. href is used for anchor tags and src is used for img tags

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.