Skip to main content

CSS Styling Images

CSS offers several ways to style images, and this lesson walks through them.


Rounded Images

Rounded images come from the border-radius property.

Tip: Shaping (clipping) images into circles, ellipses and polygons is covered in the CSS Image Shapes chapter.

Rounded Image

Rounded corners on an image take only border-radius: 8px.

Prompt
Create a page that shows an image with rounded corners using border-radius: 8px.
Output: complete HTML page

Circled Image

An image turns into a circle with border-radius: 50%.

Prompt
Create a page that shows an image styled as a circle using border-radius: 50%.
Output: complete HTML page

Thumbnail Images

Thumbnail images rely on the border property.

Thumbnail Image

A border, border-radius, and padding together turn this image into a thumbnail.

Prompt
Create a page showing an image styled as a thumbnail with a light border, border-radius, and padding.
Output: complete HTML page

Thumbnail as Link

Placing the thumbnail image inside an anchor tag turns it into a link, and box-shadow gives it a hover effect.

Prompt
Create a page showing a thumbnail image wrapped in a link. Add a hover effect with box-shadow on the image.
Output: complete HTML page

Responsive Images

An image is responsive when it adjusts on its own to fit the size of the screen.

Setting max-width: 100% and height: auto lets an image shrink whenever it has to, while stopping it from growing beyond its original size.

Tip: Responsive Web Design has its own coverage in the CSS RWD Tutorial.

Example

Prompt
Create a page with a responsive image that scales down but never larger than its original size, using max-width: 100% and height: auto.
Output: complete HTML page

Polaroid Images / Cards

A box-shadow effect plus a text caption below the image gives you a polaroid-style image card.

Example

Prompt
Create a page with two polaroid-style image cards. Each card has an image on top and a text caption below, with a box-shadow for the card effect.
Output: complete HTML page

Responsive Image Gallery

Image galleries can be made responsive with CSS too: media queries re-arrange the images for different screen sizes.

Tip: Responsive Web Design has its own coverage in the CSS RWD Tutorial.

Example

Prompt
Create a responsive image gallery using CSS. Display four images in a row on large screens, two per row on medium screens (max-width: 768px), and one per row on small screens (max-width: 480px). Use media queries.
Output: complete HTML page