CSS Properties
CSS inline-size Property
Photo Credit to CodeToFun
🙋 Introduction
The inline-size
property in CSS is used to define the horizontal or vertical size of an element, depending on the element's writing mode. In horizontal writing modes, it sets the width, and in vertical writing modes, it sets the height.
This property is particularly useful for creating responsive designs that adapt to different writing modes and screen orientations.
💡 Syntax
The syntax for the inline-size
property is simple and similar to other sizing properties in CSS. You can specify the size using various units such as pixels, percentages, ems, and more.
element {
inline-size: value;
}
Here, value can be a length, percentage, or the keywords auto, max-content, min-content, fit-content, or inherit.
🎛️ Default Value
The default value of the inline-size
property is auto, which means the size is determined by the content and other layout properties of the element.
🏠 Property Values
Value | Description |
---|---|
length | A fixed size, such as 50px or 10em. |
percentage | A size relative to the containing block, such as 50%. |
auto | The browser calculates the size. |
max-content | The size is set to the largest size the content can take without overflowing. |
min-content | The size is set to the smallest size the content can take without overflowing. |
fit-content | The size is set to fit the content within a specified limit. |
inherit | The property takes the computed value of its parent element. |
📄 Example
In this example, we'll set the inline-size
of a div to 50% of its containing element.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS inline-size Example</title>
<style>
.box {
inline-size: 50%;
background-color: lightblue;
border: 1px solid blue;
padding: 10px;
text-align: center;
}
</style>
</head>
<body>
<h1>Div with Custom Inline Size</h1>
<div class="box">
This div is 50% of its container's width.
</div>
</body>
</html>
🖥️ Browser Compatibility
The inline-size
property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. However, it is always a good practice to test your website across different browsers to ensure compatibility.
🎉 Conclusion
The inline-size
property is a versatile tool for web developers, allowing for more flexible and adaptive layouts that respond to different writing modes and screen orientations.
By understanding and utilizing this property, you can create more robust and responsive designs that enhance the user experience. Experiment with different values and see how this property can improve your web projects.
👨💻 Join our Community:
Author
For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.
Buy me a coffee to make codetofun.com free for everyone.
Buy me a Coffee
If you have any doubts regarding this article (CSS inline-size Property), please comment here. I will help you immediately.