Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS inline-size Property

Posted in CSS Tutorial
Updated on Oct 03, 2024
By Mari Selvan
👁️ 8 - Views
⏳ 4 mins
💬 1 Comment
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.

Syntax
Copied
Copy To Clipboard
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

ValueDescription
lengthA fixed size, such as 50px or 10em.
percentageA size relative to the containing block, such as 50%.
autoThe browser calculates the size.
max-contentThe size is set to the largest size the content can take without overflowing.
min-contentThe size is set to the smallest size the content can take without overflowing.
fit-contentThe size is set to fit the content within a specified limit.
inheritThe 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.

index.html
Copied
Copy To Clipboard
<!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:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

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

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy