Unable to display imported image in React application

I have a component where I want to display 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 displaying correctly as I can see it when I check the URL in the inspector.

https://i.stack.imgur.com/00lXe.png

However, on the webpage only the alt text is appearing:

https://i.stack.imgur.com/eV2Nz.png

Answer №1

It's recommended to utilize src="" rather than href="".

The href attribute is typically used to indicate the destination of a hyperlink within an anchor tag.

Answer №2

You might encounter an issue because you have utilized the incorrect attribute within your img element; opt for src instead:

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

Answer №3

Replace the href attribute with src. The href attribute is typically used for anchor tags, while src is used for img tags.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What are some strategies for accessing the original values of form components that have not been altered when using ngModel?

I am currently developing a form and I intend to utilize the previous values as "value" in the form. By employing ngModel dynamically, I am able to change some properties. However, I have encountered an issue where the field that remains unchanged by the u ...

The list marquee in HTML, JS, and CSS is not being properly rendered on

I recently made changes to a code that showcases a marquee scrolling a basic HTML list. Check it out here: I am facing 3 issues that I am struggling to resolve: JS: I want the marquee to continuously show text re-entering from the right just after it ...

The sidebar scrolling feature seems to be malfunctioning, as only the page scrolling functionality is currently

I'm currently working on a webpage that features a sidebar, along with other elements as shown below: In this design, the Your Friends section represents the sidebar. However, I have noticed that when I hover over the sidebar and try to scroll, it&ap ...

Comparison between JavaScript Promise .then(onFulfilled, onRejected) and .then(onFulfilled).catch(errorFunc) in handling asynchronous operations

As I was reviewing promises, I had a question about the order in which the .then/catch calls are executed when using the code below. Are the catch calls being placed at the end of the queue stack? I already have a clear understanding of the distinction bet ...

Enhance Express Middleware with Typescript for advanced functionality

Currently in the process of developing a REST API using Express and Typescript, I am encountering difficulties when trying to extend the Request/Response objects of Express. Although my IDE shows no errors, Typescript throws TS2339 Errors during compilati ...

Troubleshooting the fluid container problem in Bootstrap 3

I am currently working on a website using Bootstrap 3 framework. I have a specific section where I need to have two fluid containers placed side by side, each with different background colors. One of these containers should also include a background image ...

The Express server is failing to deliver a response to the client when using the fetch method

Currently, I am utilizing express for the server side of my project. To send a post request from the client to the server, I am using fetch. The data that I am sending to the server is being successfully transmitted and displayed. However, I am encounteri ...

Deployment to DigitalOcean fails due to GitHub action error

I'm encountering an issue during the deployment process to DigitalOcean via github actions and I can't figure out why it's throwing an error related to python. Could this be a result of the docker images I'm utilizing? Despite my attemp ...

Tips for separating these two words onto two separate lines

I created this box using Angular Material, but I am having trouble breaking the words "1349" and "New Feedback" into two lines. Here's an image included in my design. Any tips on accomplishing this in Angular Material? Thank you! <style> . ...

Unexpected white space appears at the bottom of the page when rotating the device in iOS Safari

One issue I encountered on my website involves a meta tag: <meta name="viewport" content="width=device-width, initial-scale=1.0"> This, combined with height:100%; on the html and body tags, causes problems when viewed on Safari ...

Redis Cache Utilization for Pagination: A Detailed Guide

I'm looking to implement pagination with Redis cache. My backend is Node.js, and I'm utilizing the npm package redis-scanner for key scanning. However, I'm currently facing a challenge in accessing a specific key and retrieving the next set ...

Creating a sticky navigation bar in a CSS Grid layout

Using a grid for the first time and attempting to make the nav-bar sticky, I initially used: position: sticky; top: 0; without any success. Subsequently, trying: position: fixed; resulted in undesired consequences. Desiring the nav-bar ...

Making HTTP requests to the localhost server using Expo SDK

I am facing an issue while trying to make HTTP requests from my Expo (React-Native) application to a node.js server running on my PC. Despite using ngrok to expose the localhost and incorporating the ngrok server in the fetch, I keep encountering a 'N ...

How can the border of the select element be removed when it is active in select2

After examining the CSS code, I am still unable to locate the specific property that is being applied to the main element. I am currently customizing the select2 library to suit my needs. However, I am stuck in the CSS as I cannot determine which property ...

Executing Child Processes in Node-Webkit

Trying to run a homebrew command, like so: brew list Followed the documentation and executed it this way: child = exec('brew', function (error, stdout, stderr) { console.log(stdout); console.log(stderr); }); Encountering a "command not foun ...

leveraging the unique MySQL id displayed within the onclick/checkbox identifier

I am currently working on a website that displays database content and enables users to click on the content to view more information related to that specific id. I also want to include a checkbox next to each piece of content that will allow me to delete ...

Nodejs server does not run service workers in offline mode

I have recently created a new project PWA. During the development phase, I did not use node js for running socket.io and the app functioned offline as expected. However, when integrated with a nodejs server, the app runs smoothly online without any issues ...

What could be the reason for the error this code is generating in the HTML validator?

As I work on creating a website that must meet W3C compliance standards, I have encountered an issue with PHP tags. The validation process runs smoothly until I insert this code snippet: <?php include 'menu.html'; ?>. An error message is ge ...

"Incorporating input boxes for MySQL updates using PHP, MySQL, and HTML

I'm looking to make my input box dynamic, where it can read the current value from the database and allow users to change that value. Currently, when I enter a number like 1000 into the input box, it posts fine. The PHP results show: Data updated: c ...

After signing out and logging back in, data fails to display - ReactJS

I am encountering difficulties with the login/logout process and displaying data in a form. When I restart my server and log in without logging out, everything works fine and the data appears in the form. However, if I log in, then log out, and log back in ...