DEV Community

Cover image for Quick VS Code tip: Automatically add image width and height to images
Christian Heilmann
Christian Heilmann

Posted on • Originally published at christianheilmann.com

1

Quick VS Code tip: Automatically add image width and height to images

One thing that keeps amazing me about Visual Studio Code is how much it helps you automate annoying tasks when you write code. For example, if you add an img tag to the document you need to know the src and find out the width and height to avoid reflow issues when the image was loaded. You also need to add an alt attribute either to provide an alternative text or to prevent assistive technology to read out the src attribute instead.

You can do this by following these steps:

  • Start the img tag
  • As soon as you write src=" VS Code gives you an autocomplete for local images.
  • Close the img tag (this is important)
  • Use the Command Palette (CMD + Shift + P on Mac or Ctrl + Shift + P on Linux / Windows) and type "size" to trigger the Emmet size script that automatically adds width and height.

You can see it in this screencast:

emmet-image-size

My setup also warns me when I have images without any alt attribute. It puts a wavy line under any element with a problem like the img tag and shows the error right next to it. I am using two extensions for this: webhint for VS Code and Error Lens.

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →