Reduce media query code

Balram Singh
Apr 21, 2022

--

Use <picture> tag instead of <img> tag in HTML

In mobile devices, we need to use smaller poster images for performance reason. Img tag allows one src while The <picture> HTML element contains zero or more <source> elements and one <img> element to offer alternative versions of an image for different display/device scenarios.

e.g:

<picture>
<source srcset="mdn-logo-wide.png" media="(min-width: 600px)">
<img src="mdn-logo-narrow.png" alt="MDN">
</picture>

Use Grid and Flex layout

Use rem and em values for fonts

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Balram Singh
Balram Singh

Written by Balram Singh

Organiser of React Scotland Meetup

No responses yet

Write a response