Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

253
Vistas
How to render different images based on screen size

I want to render a different svg based on the browser screen width. I've found a solution that expects me to use srcSet within an img tag. However, I can't get it to work.

The goal should be to render SmallTalents on mobile, and BigTalents on tablets+

Quick notes:

  • I'm using TailwindCSS.
  • The svgs are completely different, not just scaled down versions.

Example

import React from "react";
import SmallTalents from "../../../assets/smallTalents.svg";
import BigTalents from "../../../assets/bigTalents.svg";

function Example() {
  return (
    <section>
      <img
        srcSet={`${SmallTalents}, 200w ${BigTalents} 600w`}
        sizes="(max-width: 600px) 480px, 800px"
        src={SmallTalents}
        alt="talents"
      />
    </section>
  );
}

export default Example;

Update:

Tried this, not working

<picture>
  <source media="(min-width: 300px)" srcset={SmallTalents} />
  <source media="(min-width: 900px)" srcset={BigTalents} />
</picture>

Solution (not ideal)

<img src={SmallTalents} alt="talents" className="my-5 md:hidden" />
<img src={BigTalents} alt="talents" className="my-5 hidden md:flex" />
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can use picture element in html for rendering different images based on the screen size:

<picture>
  <source media="(min-width: 650px)" srcset="img_food.jpg">
  <source media="(min-width: 465px)" srcset="img_car.jpg">
  <img src="img_girl.jpg">
</picture>
about 4 years ago · Juan Pablo Isaza Denunciar

0

I think there is a small typo in your srcSet property, the 200w should be on the left side of the comma. i.e srcSet={${SmallTalents} 200w, ${BigTalents} 600w}

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda