Skip to main content

How to Change Size of Images in CSS

Images are an important part of any web page, and often you’ll need to control their size of them. You can do this in many ways, but most commonly you’ll use CSS.

CSS has two properties you can use to control the size of images: width and height. The width property sets the width of the image in pixels, while the height property sets the height of the image in pixels. You can use either property or both, to control the size of your images.

    <style text="text/css">
      .wrapper{margin: 2em; font-family: sans-serif;}
        margin-bottom: 1em;
      .img-wrapper img{
        border: 1px solid red;
      #img1{width: 300px;}
      #img1 img{width: 100%;}
      #img2{width: 500px;}
      #img2 img{width: 200px;}
      #img3{width: 500px;}
      #img3 img{height: 400px; max-width: 500px;}

    <div class="wrapper">
      <div class="img-wrapper" id="img1">
        <img src="" />
      <div class="img-wrapper" id="img2">
        <img src="" />
      <div class="img-wrapper" id="img3">
        <img src="" />

Remember, you can always use multiple rules to target specific images if you need to. For example, if you only want to resize certain images on your page, you could add a class or ID to those images and then create a rule specifically for them. This gives you a lot of flexibility in how you control the size of your images.

By continuing to use the site, you agree to the use of cookies.