PDF download Download Article PDF download Download Article

The width and height attributes in HTML specify the size of an image in pixels. In HTML 4.01, the height could be defined in pixels or in % of the containing element. In HTML5, the value must be in pixels. This wikiHow teaches you how to specify the size of an image in your HTML code.

  1. Step 1 Open your HTML document a text editor.
    Windows and Mac computers come with default text editor programs like Notepad and Text Edit that will work to create or edit HTML. You can either open the HTML document within the program by clicking Open from the File tab, or you can right-click the file in your file browser and click Open With….
  2. <img src="imagefile.jpg" alt="Image" height="42" width="42">
    • src is the file path to your image.
    • alt is the tag you give for image.
    • Note that those numbers are in pixels.
    • You can also use the style tag. For example, you'd have the following code in your text: <img src="imgfile.jpg" alt="Image" style="width:500px;height:600px;">. The style tag ensures the image stays that size and overrides any further image size commands.[1]
    Advertisement
  3. For example, if you enter 21 in the width and 21 in the height areas, you'll get an image half the size as the original.
  4. Save the file and open the file using any browser to see the effect. If you don't like the size of the image, you can repeat the previous steps.[2]
  5. Advertisement

Community Q&A

Search
Add New Question
  • Question
    I tried it, and my image is the word "image". Any ideas?
    Community Answer
    Community Answer
    Make sure that the image that you want to use is stored in the same folder as the HTML document. Also, make sure that you have put the right file name in the actual HTML coding.
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement

Tips

  • Always specify both the height and width attributes for images. If height and width are set, the space required for the image is preserved when the page is loaded. However, without these attributes, the browser does not know the size of the image, and cannot reserve the appropriate space to it. The effect will be that the page layout will change during loading (while the images load).
  • Downsizing a large image with the height and width attributes forces a user to download the large image (even if it looks small on the page). To avoid this, rescale the image with a program before using it on a page.
Submit a Tip
All tip submissions are carefully reviewed before being published
Name
Please provide your name and last initial
Thanks for submitting a tip for review!
Advertisement

You Might Also Like

Insert Images with HTMLInsert Images with HTML
Embed Pictures Embed Images in Documents and Websites
Resize iFrames in HTMLResize iFrames in HTML
Set a Background Image in HTMLAdd a Background Image to a Website: Step-by-Step Tutorial
Make a Picture Link in HTMLMake a Picture Link in HTML
Resize an Image in Adobe PhotoshopResize an Image in Adobe Photoshop
Resize a JPEG Resize JPEGs Using a Browser, Windows, Mac, or Mobile Device
Create Redirects in HTMLCreate Redirects in HTML
Create a Simple CSS Stylesheet Using NotepadCreate a Simple CSS Stylesheet Using Notepad
Downsize PhotosDownsize Photos
Edit HTML FilesEdit HTML Files
Center an Image in HTMLCenter an Image in HTML
Write HTML CodeWrite HTML Code
Resize Pictures (for Macs)Easy Ways to Resize an Image on a Mac (Without Buying Software)
Advertisement

About This Article

Darlene Antonelli, MA
Written by:
wikiHow Technology Writer
This article was co-authored by wikiHow staff writer, Darlene Antonelli, MA. Darlene has been writing and editing tech content at wikiHow since 2019. She previously worked for AppleCare, served as a writing tutor, volunteered in IT at an animal rescue, and taught as an adjunct professor for EN101 and EN102. Darlene has completed Coursera courses on technology, writing, and language. She holds both a BA (2011) and an MA (2012) from Rowan University in Writing, with a focus on workplace communication. With her extensive experience, academic background, and ongoing learning, Darlene has become the go-to grammar expert for her friends and family, as well as a skilled wordsmith for anyone in need. This article has been viewed 198,071 times.
How helpful is this?
Co-authors: 6
Updated: August 29, 2019
Views: 198,071
Categories: HTML
Article SummaryX

1. Open the HTML document in a text editor.
2. Add <img src="imagefile.jpg" alt="Image" height="42" width="42">.
3. Change the numbers for height and width to change the size.
4. Save the HTML file.

Did this summary help you?

Thanks to all authors for creating a page that has been read 198,071 times.

Is this article up to date?

Advertisement