Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • CSS Tutorial
  • CSS Exercises
  • CSS Interview Questions
  • CSS Selectors
  • CSS Properties
  • CSS Functions
  • CSS Examples
  • CSS Cheat Sheet
  • CSS Templates
  • CSS Frameworks
  • Bootstrap
  • Tailwind
  • CSS Formatter
Open In App
Next Article:
Interesting Facts About CSS Text Styling
Next article icon

Interesting Facts About CSS Image Styling

Last Updated : 26 Feb, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

CSS provides a variety of ways to manipulate and enhance images in your layouts. Let’s explore some facts that will help you improve your image styling and create more dynamic, engaging websites.

1. Control Image Aspect Ratio with aspect-ratio

The aspect-ratio property is a game-changer for maintaining consistent image proportions, ensuring your images are responsive and always look well-aligned.

  • Maintain Proportions: Use aspect-ratio to control the width and height ratio of your images.
  • Responsive Design: Ensures images resize correctly on different screen sizes.
  • No Extra Containers Needed: Unlike older methods, this doesn’t require wrapping elements or padding hacks.
HTML
<html> <head>     <style>         img {             width: 100%;             aspect-ratio: 16 / 9;             object-fit: cover;         }     </style> </head> <body>     <img  src="https://media.geeksforgeeks.org/wp-content/uploads/20241129170413217901/InterestingFactsAboutCSS-min-1024x566_11zon.jpg"       alt="Image example"> </body> </html> 
  • The aspect-ratio: 16 / 9 ensures the image keeps a 16:9 ratio no matter the width of the container.
  • object-fit: cover ensures the image fully covers the space without stretching, while maintaining the aspect ratio.

2. Control How an Image Fills Its Container with object-fit

The object-fit property is a simple yet powerful way to control how images scale and fill their container, whether you want them to stretch, cover, or contain.

  • Fit the container: object-fit: cover ensures the image covers the container, cropping it as needed.
  • Contain within bounds: object-fit: contain ensures the whole image is visible without stretching.
  • Responsive control: Perfect for responsive designs where you need images to adjust to various container sizes.
HTML
<html> <head>     <style>         img {             width: 100%;             height: 300px;             object-fit: cover;         }     </style> </head> <body>     <img src="https://media.geeksforgeeks.org/wp-content/uploads/20241129170413217901/InterestingFactsAboutCSS-min-1024x566_11zon.jpg"          alt="Image example"> </body> </html> 
  • object-fit: cover ensures that the image covers the entire container, even if part of it gets cropped.
  • The image resizes to maintain its aspect ratio and cover the entire available space.

3. Apply Effects to Images with CSS Filters

CSS filters like blur, brightness, and contrast provide a simple way to apply effects directly to images, giving you more creative control.

  • Image enhancement: Use filter to adjust the appearance of images, such as adding a blur effect or increasing contrast.
  • Dynamic effects: Filters can be applied on hover for interactive effects.
  • No need for extra software: Filters are native CSS properties, so they don’t require external libraries or tools.
HTML
<html> <head>     <style>         img {             width: 100%;             height: 300px;             transition: filter 0.3s ease;         }         img:hover {             filter: blur(5px) brightness(80%);         }     </style> </head> <body>     <img  src="https://media.geeksforgeeks.org/wp-content/uploads/20241129170413217901/InterestingFactsAboutCSS-min-1024x566_11zon.jpg"          alt="Image example"> </body> </html> 


  • filter: blur(5px) applies a blur effect on hover, and brightness(80%) darkens the image.
  • The transition property adds a smooth effect when hovering.

4. Round Image Corners with border-radius

The border-radius property allows you to easily round the corners of your images, adding a soft, modern touch to your design.

  • Rounded corners: Use border-radius to create rounded edges, giving the image a more polished and soft look.
  • Circular images: Set border-radius: 50% to create perfectly circular images.
  • Works on all images: This can be applied to any image in your layout, whether it’s a profile picture or a banner image.
HTML
<html> <head>     <style>         img {             width: 200px;             height: 200px;             border-radius: 50%;         }     </style> </head> <body>     <img  src="https://media.geeksforgeeks.org/wp-content/uploads/20241129170413217901/InterestingFactsAboutCSS-min-1024x566_11zon.jpg"           alt="Image example"> </body> </html> 
  • border-radius: 50% makes the image circular, which is commonly used for profile pictures or icons.



Next Article
Interesting Facts About CSS Text Styling

A

anujpaz9pe
Improve
Article Tags :
  • CSS
  • Web Technologies

Similar Reads

  • Interesting Facts About CSS Text Styling
    CSS text styling provides a wide range of options to enhance and customize the text in your layouts. Let’s explore some interesting facts and tricks to improve your text styling skills. 1. Use text-shadow for Subtle EffectsThe text-shadow property is often underused but can add a nice depth to the t
    3 min read
  • CSS Styling Images
    CSS allows you to apply various styles to images, making them more responsive, visually appealing, and interactive. You can modify the appearance and behaviour of images on your webpage by using CSS properties like border-radius, box-shadow, filter, and others. Thumbnail ImagesThe border property he
    3 min read
  • How to add image refaction using CSS ?
    This article will show how to add image reflection using CSS. To achieve this task, you can use the -webkit-box-reflect to add the reflection of any HTML element. The box-reflect property is a CSS property that allows you to create a reflection effect for an element. It is primarily used to add a mi
    2 min read
  • How to resize list style image in CSS ?
    In this article, we will learn to set an image or icon as the <li> image. We need to set the size of the custom list image to make it attractive. So, we will also learn the different ways to resize the custom list image. Syntax: In this article, we will use below CSS properties. background-ima
    3 min read
  • How to Change an Input Button Image using CSS?
    Changing an input button image using CSS allows developers to replace the default button style with a custom image. This enhances the button's appearance and improves user interaction. CSS properties like background-image and hover effects enable dynamic and visually appealing button designs for web
    2 min read
  • How to Add Visual Effects to Images using CSS?
    CSS is most useful for adding visual effects to images, enhancing the overall user experience. By using CSS properties like filter, transform, and transition, you can create dynamic and engaging effects that respond to user interactions. In this article, we will explore examples showcasing the visua
    2 min read
  • How to Adjust Image Size in CSS?
    Adjusting the image size using CSS is a common task for web developers when designing responsive and visually appealing web pages. CSS can provide several ways to manipulate the dimensions of the image, including setting fixed sizes, scaling, or making them responsive to the container they are in. W
    5 min read
  • How to Add Image in Text Background using HTML and CSS ?
    In this article, we will use HTML and CSS to set the image in the text background. To set the image in the text background, some CSS property is used. To add an image in the text background using HTML and CSS, create a container element (e.g., a `<div>`), set its background to the desired imag
    2 min read
  • How to Add filter to the background image using CSS?
    Adding filters to background images using CSS allows you to apply visual effects like blur, grayscale, brightness adjustment, and more without modifying the actual image file. CSS provides a set of filter functions that can be applied to elements with background images. This approach enhances design
    3 min read
  • How to repeat border image using CSS ?
    You can repeat border images using the border-image-repeat property in CSS. It is generally used for scaling and tiling the border-image. It is used to match the middle part of the border-image to the size of the border. Syntax:border-image-repeat: stretch|repeat|round|initial|inheritNote: The borde
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences