Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST TOOLS

W3.CSS Images

Images

W3.CSS provides classes for styling responsive and attractive images.

Images can have rounded corners, borders, cards, effects, and overlays.

Responsive Images

The w3-image class makes an image responsive.

The image will scale down when necessary, but it will not become larger than its original size.

Northern Lights

Example

<img src="img_lights.jpg" alt="Northern Lights" class="w3-image">
Try it Yourself »

Note

Responsive images help prevent images from becoming wider than their containers.


Full Width Images

Use width:100% when you want an image to fill the width of its container.

Northern Lights

Example

<img src="img_lights.jpg" alt="Northern Lights" style="width:100%">
Try it Yourself »

Maximum Image Width

You can combine width:100% with max-width to make an image responsive without letting it become too large.

Northern Lights

Example

<img src="img_lights.jpg" alt="Northern Lights" style="width:100%;max-width:400px">
Try it Yourself »

Rounded Images

The w3-round class adds rounded corners to an image.

Norway

Example

<img src="image.jpg" class="w3-image w3-round" alt="Norway">
Try it Yourself »

Circled Images

The w3-circle class shapes an image into a circle.

Norway

Example

<img src="img_snowtops.jpg" class="w3-image w3-circle" alt="Norway" style="width:250px;height:250px;object-fit:cover">
Try it Yourself »

The object-fit Property

The CSS property object-fit:cover; scales an image to fill its container while preserving its original aspect ratio. If the image does not match the aspect ratio of its container, the image is cropped along the edges to prevent any stretching distortion.

For a perfect circle, the image should have the same width and height.


Bordered Images

Use w3-border to add a border around an image.

Padding can be added to create a thumbnail effect.

Norway

Example

<img src="img_snowtops.jpg" class="w3-border w3-padding" alt="Norway">
Try it Yourself »

Image as a Card

Combine an image with w3-card to create a simple image card.

Person

Simon

The boss of all bosses

Example

<div class="w3-card">
  <img src="img_avatar.png" alt="Person" style="width:100%">
  <div class="w3-container">
    <h3>Simon</h3>
    <p>The boss of all bosses</p>
  </div>
</div>
Try it Yourself »


Text on an Image

Use w3-display-container and display classes to position content over an image.

Northern Lights

Norway

Northern Lights

Example

<div class="w3-display-container w3-text-white">
  <img src="img_lights.jpg" alt="Lights" style="width:100%">
  <div class="w3-display-bottomleft w3-container">
    Norway
  </div>
</div>
Try it Yourself »

You learned more about display positioning in the W3.CSS Display chapter.


Image Opacity

The w3-opacity classes make images transparent:

Forest

w3-opacity-min

Forest

w3-opacity

Forest

w3-opacity-max

Example

<img src="image.jpg" class="w3-image w3-opacity-min">
<img src="image.jpg" class="w3-image w3-opacity">
<img src="image.jpg" class="w3-image w3-opacity-max">
Try It Yourself »

Image Hover Effects

Image effects can also be applied when the user moves the mouse over an image.

Norway

w3-hover-opacity

Norway

w3-hover-grayscale

Norway

w3-hover-sepia

Example

<img src="image.jpg" class="w3-image w3-hover-opacity" alt="Norway">
<img src="image.jpg" class="w3-image w3-hover-grayscale" alt="Norway">
<img src="image.jpg" class="w3-image w3-hover-sepia" alt="Norway">
Try it Yourself »

What You Have Learned

  • w3-image makes an image responsive
  • w3-round adds rounded corners
  • w3-circle creates circular images
  • w3-border adds an image border
  • Images can be displayed as cards
  • Display classes can position text over images
  • Opacity, grayscale, and sepia classes create image effects
  • Hover classes can create interactive image effects

More Examples

Explore more ways to style W3.CSS images.


Grayscale Levels

The w3-grayscale classes add a grayscale effect to an image:

Normal

w3-grayscale-min

w3-grayscale

w3-grayscale-max

Example

<img src="image.jpg" class="w3-image w3-grayscale-min">
<img src="image.jpg" class="w3-image w3-grayscale">
<img src="image.jpg" class="w3-image w3-grayscale-max">
Try it Yourself »

Sepia Levels

The w3-sepia classes add a sepia effect to an element.

Normal

w3-sepia-min

w3-sepia

w3-sepia-max

Example

<img src="image.jpg" class="w3-image w3-sepia-min">
<img src="image.jpg" class="w3-image w3-sepia">
<img src="image.jpg" class="w3-image w3-sepia-max">
Try it Yourself »

Hover On/Off

The w3-hover-opacity class adds transparency to the image on mouse-over.

The w3-hover-opacity-off class removes transparency on mouse-over.

Add transparency on hover:

Norway

Remove transparency on hover:

Norway

Example

<img src="snowtops.jpg" class="w3-hover-opacity" alt="Alps">
<img src="snowtops.jpg" class="w3-opacity w3-hover-opacity-off" alt="Alps">
Try It Yourself »

Photo Album

Images, cards, and the W3.CSS responsive layout classes can be combined to create a photo album.

Cinque Terre

5 Terre

Monterosso

Monterosso

Vernazza

Vernazza

Example

<div class="w3-third">
  <div class="w3-card">
    <img src="img_monterosso.jpg" style="width:100%">
    <div class="w3-container">
      <p>Monterosso</p>
    </div>
  </div>
</div>
Try it Yourself »

You will learn more about responsive layouts later in this tutorial.


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

```