Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS inset-block Property

Posted in CSS Tutorial
Updated on Oct 03, 2024
By Mari Selvan
👁️ 7 - Views
⏳ 4 mins
💬 1 Comment
CSS inset-block Property

Photo Credit to CodeToFun

🙋 Introduction

The inset-block property in CSS is part of the Logical Properties and Values specification. It allows developers to control the logical block-start and block-end offsets of an element in a single declaration.

This property is particularly useful for handling layouts in a way that adapts to different writing modes, such as left-to-right, right-to-left, and vertical text directions.

💡 Syntax

The syntax for the inset-block property is straightforward. It can take one or two values.

Syntax
Copied
Copy To Clipboard
element {
  inset-block: value;
}

element {
  inset-block: block-start-value block-end-value;
}
  • value: Specifies the offset for both the block-start and block-end edges.
  • block-start-value block-end-value: Specifies the offset for the block-start and block-end edges individually.

🎛️ Default Value

The default value of the inset-block property is auto, which means the element's position will be determined by the browser's default styles or other specified properties.

🏠 Property Values

ValueDescription
lengthSpecifies a fixed offset, such as 20px, 1em, 5%, etc.
autoThe browser calculates the offset automatically.
initialSets the property to its default value.
inheritInherits the value from its parent element.

📄 Example

In this example, we'll apply the inset-block property to position an element within its container.

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 inset-block Example</title>
  <style>
    .container {
      position: relative;
      width: 300px;
      height: 200px;
      border: 1px solid #000;
    }
    .box {
      position: absolute;
      inset-block: 10px 20px;
      width: 100px;
      height: 50px;
      background-color: #007bff;
    }
  </style>
</head>
<body>
  <h1>Element with inset-block Property</h1>
  <div class="container">
    <div class="box"></div>
  </div>
</body>
</html>

🖥️ Browser Compatibility

The inset-block 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 inset-block property is a versatile tool for web developers looking to manage the block-level positioning of elements in a logical, writing-mode independent manner.

By understanding and using this property, you can create more flexible and robust layouts that adapt to different writing modes and languages. Experiment with different values and see how this property can enhance your web designs.

👨‍💻 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