THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

CSS Images


Learn how to style images using CSS.


Rounded Images

Use the border-radius property to make adjusted images:


adventure cold

Example

Rounded Image:

img {
    outskirt span: 8px;
}
adventure cold

Example

Circled Image:

img {
    fringe range: 50%;
}
Try it Yourself »

Thumbnail Images

Use the border property to make thumbnail images.

Thumbnail Image:

adventure cold

Example

img {
    outskirt: 1px strong #ddd;
    outskirt sweep: 4px;
    cushioning: 5px;
}

<img src="adventure cold.jpg" alt="adventure cold">
Try it Yourself »

Thumbnail Image as Link:

Example

a {
    show: inline-block;
    fringe: 1px strong #ddd;
    fringe range: 4px;
    cushioning: 5px;
    progress: 0.3s;
}

a:hover {
    box-shadow: 0 0 2px 1px rgba
    (0, 140, 186, 0.5);
}

<a href="paris.jpg">
  <img src="adventure cold.jpg" alt="adventure cold">
</a>
Try it Yourself »

Responsive Images

Responsive pictures will consequently acclimate to fit the measure of the screen.

Resize the program window to see the effect:

arts-and-makes books-plan

If you need a picture to downsize in the event that it needs to, yet never scale up to be bigger than its unique size, include the following:

Example

img {
    max-width: 100%;
    tallness: auto;
}
Try it Yourself »

Tip: Read progressively about Responsive Web Design in our CSS RWD Tutorial.


Polaroid Images/Cards

architecture

architecture, building

acrylic

acrylic craftsmanship arts

Example

div.polaroid {
    width: 80%;
    foundation shading: white;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

img {width: 100%}

div.container {
    content adjust: center;
    cushioning: 10px 20px;
}
Try it Yourself »

Image Filters

The CSS filter property includes special visualizations (like haze and immersion) to an element.

Note: This property isn't upheld in Internet Explorer or Safari 5.1 (and earlier).

Example

Change the shade of all pictures to high contrast (100% gray):

img {
    - webkit-channel: grayscale(100%);/* Chrome, Safari, Musical drama */
    channel: grayscale(100%);
}
Try it yourself »

Responsive Image Gallery

CSS can be utilized to make picture exhibitions. This precedent use media questions to re-organize the pictures on various screen sizes. Resize the program window to see the effect:

adult-refreshment clear
Add a portrayal of the picture here
attractive-delightful
Add a portrayal of the picture here
asphalt-condition mist
Add a portrayal of the picture here
agriculture-nation farmland
Add a portrayal of the picture here

Example

.responsive {
    cushioning: 0 6px;
    drift: left;
    width: 24.99999%;
}

@media just screen and (max-width: 700px){
    .responsive {
        width: 49.99999%;
        edge: 6px 0;
    }
}

@media just screen and (max-width: 500px){
    .responsive {
        width: 100%;
    }
}
Try it yourself »

Tip: Read increasingly about Responsive Web Design in our CSS RWD Tutorial.


Image Modal (Advanced)

This is a guide to exhibit how CSS and JavaScript can function together.

First, use CSS to make a modular window (discourse box), and conceal it by default.

Then, utilize a JavaScript to demonstrate the modular window and to show the picture inside the modular, when a client taps on the image:

arts and makes books structure

Example

/Get the modal
var modular = document.getElementById('myModal');

//Get the picture and supplement it inside the modular - utilize its "alt" message as a caption
var img = document.getElementById('myImg');
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");
img.onclick = function(){
    modal.style.display = "block";
    modalImg.src = this.src;
    modalImg.alt = this.alt;
    captionText.innerHTML = this.alt;
}

/Get the <span> component that shuts the modal
var length = document.getElementsByClassName("close")[0];

//When the client clicks on <span> (x), close the modal
span.onclick = work() {
    modal.style.display = "none";
}
Try it yourself »