How to change image size in CSS?26 Mar 2025 | 2 min read Sometimes, it is required to fit an image into a certain given dimension. We can resize the image by specifying the width and height of an image. A common solution is to use the max-width: 100%; and height: auto; so that large images do not exceed the width of their container. The max-width and max-height properties of CSS works better, but they are not supported in many browsers. Another way of resizing the image is by using the object-fit property, which fits the image. This CSS property specifies how a video or an image is resized to fit its content box. It defines how an element fits into the container with an established width and height. The object-fit property is generally applied to image or video. This property defines how an element responds to the width and height of its container. Mainly there are five values of object-fit property such as fill, contain, cover, none, scale-down, initial, and inherit. The default value of this property is "fill". ExampleIn this example, we are resizing the image by using the max-width: 100%; and height: auto; properties. Output ![]() ExampleIn this example, we are using the object-fit: cover; property. Output ![]() In the above example, we have used the cover value of the object-fit property. Similar to the above example, we can use the other values of the object-fit property in order to resize the image. Next TopicHow to change link color in CSS |
Introduction The idea of transparent backgrounds in CSS emerges as an effective tool in the dynamic world of online design, where aesthetics and user interaction rule supreme. Designers may create fascinating visual narratives that improve websites' overall appearance and user experience by expertly combining elements with different...
3 min read
To construct a button in HTML, we use the button tag. However, we may customize the buttons using CSS attributes. We can develop user interaction and event processing with the aid of buttons. They are one of the most often utilized components on websites. Typically, buttons are...
4 min read
Introduction Nowadays, most visitors open the website on their phone. But the website was created in the past, so we could only open part of the website on a mobile phone. We have to zoom in to read or visit proposals on the website. But presently, all...
8 min read
Freelate One of the primary methods for applying styles to HTML components is using CSS type selectors. A type selector uses the name of the HTML tag to target specific items. It enables you to add styles to any element in your HTML page that uses a...
4 min read
What is ? A CSS portal is a web-based interface or platform enabling users to access and engage with content and services related to Cascading Style Sheets (CSS). The visual style and layout of web pages are specified using the coding language CSS. Users may be able...
6 min read
Introduction The set of styles, attributes, and layout directives known as CSS profiles are used to define web pages' visual presentation and appearance. These profiles are essential to web development because they let programmers separate a website's presentation from its information, allowing for a more effective and...
6 min read
? The font property in CSS is used to control the look of texts. By using it, we can change the text size, color, style, and more. This CSS property is a shorthand property and combines the sub-properties (that are font-style, font-variant, font-weight, font-stretch, font-size, line-height,...
3 min read
? The use of tables in the designing of a website is an exciting task. By default, the alignment of a table is towards the left, but by using the margin property in CSS, we can align it at the center. If we set the value of...
1 min read
? In HTML, the <center> tag is used to center an element. The correct and modern way to center text is by using the CSS properties. It can be of the easiest task, but when we have more elements or large code, it can sometimes be...
1 min read
What is CSS Id Selector? In CSS, the id selector helps us to target and style particular html elements based on the distinctive ID attribute. In CSS, we can give each element a distinct ID by using the id attribute in HTML. There should never be two...
6 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India