I bet you don't know how powerful the <img> tag is.

Let's find out 👇
Here is the most simple case of using it.

If the path is correct, the browser will display a picture of the mobile phone.

So far so good.
Now, we forgot to specify the alt tag for better accessibility.

There are two important rules:

1. You should always specify it

2. If the picture serves decorative purpose, you should put an empty alt, so that screen readers don't read it.
If we place an image the way we did, we have two problems:

1. The image will be rendered to its full width and height

2. There will be a layout shift since the browser doesn't know how much space to reserve for the image, until it loads it

So we should specify dimensions.
But what if we want to display different images for desktop and mobile?

This is the so-called "Art direction problem"

For mobile we can:

1. Serve more lightweight image
2. Show cropped version of image focusing on the main aspect

We can solve this in two ways. 👇
The first is using the "srcset" and "sizes" attributes.

srcset: one or more strings separated by commas, indicating possible image sources for the user agent to use.

sizes: One or more strings separated by commas, indicating a set of source sizes.
Another approach is using <picture> tag.

This approach looks much cleaner for me.
What's the difference between these two approaches?

They do the same work, but have a difference:

🔸<picture> dictates what image the browser should use

🔸srcset gives the browser a choice. So this is a recommendation for the browser.
If you have images placed below the fold they will be loaded even if the user hasn't scrolled down.

That will result in huge traffic data loading right away.

To prevent this, you can set the loading attribute to "lazy"
There is also a cool decoding attribute.

When the browser downloads an image it has to decode it first before showing it.

Sync decoding:

text -> image decoding -> image -> text

Async: the image decoding will be deferred and run asynchronously.
So, we started from simple <img src="phone.jpg">.

Look what we have now!

And we didn't work on image placeholders (that's another topic I'll cover later).

Of course, this is a sample snippet, you can have much more sources and different configurations.

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Victor

Victor Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @vponamariov

7 May
Collection of advanced UI/UX articles for reading on the weekend 🤓

Don't forget to bookmark👇
🔸What is zero UI? careerfoundry.com/en/blog/ui-des…

🔸Compensatory vs Noncompensatory: 2 Decision-Making Strategies
nngroup.com/articles/compe… from @NNgroup

🔸A Guide To Optimizing Images For Mobile smashingmagazine.com/2019/10/imagek… from @smashingmag
🔸Best practice for date-of-birth form fields blog.prototypr.io/best-practice-… from @Prototypr

🔸Building Your Color Palette refactoringui.com/previews/build… from @steveschoger

🔸 Modal & Nonmodal Dialogs: When (& When Not) to Use Them nngroup.com/articles/modal… from @NNgroup
Read 4 tweets
6 May
My personal list of top accessibility resources 👇
1. w3.org/WAI/standards-… - WCAG standards

2. webaim.org from @webaim - one of the leading providers of web accessibility expertise internationally

3. myaccessible.website - A very nice site explaining a11y in human language by @myaccessibleweb
4. nngroup.com/topic/accessib… - some articles from @NNgroup

5. webaccess.berkeley.edu/resources - tons of resources by @UCBerkeley

6. a11yproject.com - the name speaks for itself. Follow them here @A11YProject
Read 6 tweets
5 May
I want to share with you something private.

I remember when I was ~13-15 I was learning HTML/CSS/PHP.

My parents thought that this is childish, it has nothing to do with "real coding".

They told me that real coders use deep math and binary code.
So I was demotivated a bit. But now this is what I do for my living.

Then I started building sites, and I was learning SEO.

My father told me: "How is going to visit your site about learning English?".

I ended up with 4000 uniques/day and significantly improved my English
Then, I remember I wanted to go to English courses and pass FCE/CAE certificates.

When I found a cool English school in Moscow, my father told me: "what a suspicious company! Who needs the certificates? Who told you they are accepted worldwide?"

Now I write tweets in English
Read 5 tweets
4 May
10 simple rules to make your site more accessible 👇
1/10

The site should be accessible via keyboard without using a mouse.

This is easy to test - simply try to use your own site without a mouse & touchpad.
2/10

Use proper alt text for all images

Alt text should be provided for images, so that screen reader users can understand the message conveyed by the images.

If an image serves decorative purposes, use an empty string as the alt tag.
Read 14 tweets
27 Apr
15 Common CSS mistakes developers make 👀

👇
1. Not using a CSS reset

Each browser has its own default styling for HTML elements.

I'd say it's not just good practice, it's a MUST to reset the styling to some default values and then start styling from scratch

That will help:
necolas.github.io/normalize.css/
2. Starting with the desktop version

It’s easier to develop for a small screen before scaling the design up to a large screen.

You can always make existing elements bigger to fill a blank space on a larger screen.

But it's harder to do it vice versa.
Read 16 tweets
23 Apr
How user interface evolved for the past 40 years ✨

Visual Thread 🧵
Xerox 8010 Star, released in 1981

It was the first commercial personal computer that had
such things as

- window-based graphical user interface
- icons
- folders
- mouse (two-button)
- Ethernet networking
- file servers
- print servers
- e-mail.
Apple Lisa Office System 1. Released on January 19, 1983.

It is one of the first personal computers to present a graphical user interface (GUI) in a machine aimed at individual business users.
Read 17 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(