What is Inset Block?
The inset-block CSS property is a shorthand logical property that defines the logical block start and block end offsets of an element. It combines inset-block-start and inset-block-end into a single declaration, making your CSS more concise and maintainable.
Unlike traditional physical properties like top and bottom, inset-block adapts to the element's writing mode, making it essential for building truly internationalized layouts that support languages with different text directions. This approach aligns with modern web development practices where internationalization is a key consideration for global audiences.
Logical Properties vs Physical Properties
To understand inset-block, you first need to understand the distinction between logical and physical properties in CSS. Traditional CSS properties like top, right, bottom, and left are physical properties. They always refer to the physical orientation of the viewport, regardless of how the content flows.
Logical properties, on the other hand, are direction-relative. They adapt to the writing mode, direction, and text orientation of the content they affect. This means the same logical property can refer to different physical edges depending on the context.
For example:
inset-blockcorresponds totopandbottomin horizontal writing modesinset-blockcorresponds torightandleftin vertical writing modes
This dynamic behavior is what makes logical properties so powerful for internationalization. When you use inset-block, you're defining the block-direction offsets without hardcoding them to specific physical edges.
Key benefits for modern web development
Internationalization
Create layouts that work seamlessly across LTR and RTL languages without separate stylesheets.
Vertical Writing Modes
Support languages like Japanese and Chinese that use vertical text layouts.
Future-Proof Code
Write CSS that adapts to evolving web standards and writing modes.
Cleaner Syntax
Reduce code complexity with shorthand properties for common positioning patterns.
Syntax and Values
The inset-block property follows a straightforward syntax that accepts various value types, making it flexible for different positioning scenarios.
Basic Syntax
inset-block: <block-start> <block-end>;
You can specify both values, or if both block start and block end are the same, you can provide a single value that applies to both.
Accepted Value Types
The inset-block property accepts the same value types as the traditional top and bottom properties:
Length Values:
inset-block: 10px 20px;
inset-block: 2.5em 1.5rem;
inset-block: 3rem;
Percentage Values:
inset-block: 10% 5%;
Percentages are calculated relative to the containing block's logical height, which means they adapt appropriately when the writing mode changes.
Keyword Values:
inset-block: auto;
The auto keyword is the initial value, meaning the browser calculates the position based on normal flow or other positioning rules.
Global Values:
inset-block: inherit;
inset-block: initial;
inset-block: revert;
inset-block: revert-layer;
inset-block: unset;
Constituent Properties
As a shorthand, inset-block sets two individual properties:
- inset-block-start: Defines the offset from the block-start edge of the containing block
- inset-block-end: Defines the offset from the block-end edge of the containing block
You can also set these properties individually if you need more granular control:
inset-block-start: 20px;
inset-block-end: 10px;
1/* Basic usage */2.element {3 inset-block: 20px 40px;4 position: relative;5}6 7/* Single value for both */8.element {9 inset-block: 1rem;10 position: absolute;11}12 13/* Percentage values */14.element {15 inset-block: 10% 5%;16 position: fixed;17}18 19/* Auto value */20.element {21 inset-block: auto;22 position: relative;23}Writing Mode Interactions
One of the most powerful aspects of inset-block is how it adapts to different writing modes. Understanding these interactions is key to leveraging the property effectively.
Horizontal Writing Mode (default)
In the default horizontal writing mode (writing-mode: horizontal-tb), text flows from left to right horizontally, and blocks stack vertically from top to bottom. In this context:
inset-block-startcorresponds totopinset-block-endcorresponds tobottom
Vertical Right-to-Left (vertical-rl)
In vertical right-to-left writing modes (common in traditional Japanese and Chinese), text flows vertically from right to left. In this context:
inset-block-startcorresponds torightinset-block-endcorresponds toleft
Vertical Left-to-Right (vertical-lr)
In vertical left-to-right writing modes (used in some Mongolian scripts), text flows vertically from left to right. In this context:
inset-block-startcorresponds toleftinset-block-endcorresponds toright
Understanding these mappings is essential when building layouts for multilingual websites that serve diverse audiences across different regions.
1/* Horizontal writing mode */2.box-horizontal {3 position: absolute;4 inset-block: 30px 50px;5 writing-mode: horizontal-tb;6}7 8/* Vertical right-to-left */9.box-vertical-rl {10 position: absolute;11 inset-block: 30px 50px;12 writing-mode: vertical-rl;13}14 15/* Vertical left-to-right */16.box-vertical-lr {17 position: absolute;18 inset-block: 30px 50px;19 writing-mode: vertical-lr;20}21 22/* Sticky header */23.sticky-header {24 position: fixed;25 inset-block-start: 0;26 width: 100%;27 background: white;28}29 30/* Centered modal */31.modal {32 position: fixed;33 inset-block: 50%;34 inset-inline: 50%;35 transform: translate(-50%, -50%);36}Practical Use Cases
Sticky Headers and Navigation
When building sticky headers that should remain visible as users scroll, inset-block provides a clean solution that works regardless of writing mode:
.sticky-header {
position: fixed;
inset-block-start: 0;
inset-block-end: auto;
width: 100%;
background: white;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
This approach ensures the header sticks to the top in horizontal layouts and would adapt appropriately if the writing mode changes.
Full-Bleed Overlays
Creating full-bleed overlays that cover the entire viewport works elegantly with inset-block:
.overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
}
Card Components with Badges
Creating card components with badges positioned in the block direction:
.badge {
position: absolute;
inset-block-start: -0.5rem;
inset-inline-end: 1rem;
padding: 0.25rem 0.75rem;
background: #007bff;
color: white;
border-radius: 9999px;
}
Sidebar Layouts
Building sidebar layouts that adapt to writing modes:
.sidebar {
position: sticky;
inset-block-start: 2rem;
height: fit-content;
}
These patterns ensure your components work correctly across different writing modes without requiring separate stylesheets or complex CSS overrides.
Browser Support and Compatibility
The inset-block property has excellent support across modern browsers, making it safe to adopt in production projects.
Current Browser Support
According to MDN's browser compatibility data:
| Browser | Version | Release Date |
|---|---|---|
| Chrome | 87+ | December 2020 |
| Firefox | 66+ | March 2019 |
| Safari | 14.1+ | April 2021 |
| Edge | 87+ | December 2020 |
| Opera | 73+ | December 2020 |
Baseline Status
The inset-block property achieved "Baseline" status in April 2021, indicating:
- Consistent behavior across browsers
- Available in stable versions of all major browsers
- No known interoperability issues
- Stable specification
Fallback Strategy
For projects that need to support older browsers, use progressive enhancement:
.element {
/* Fallback for older browsers */
top: 20px;
bottom: 40px;
/* Modern browsers will use inset-block */
inset-block: 20px 40px;
}
You can also use @supports for feature detection:
@supports (inset-block: 0) {
.element {
inset-block: 20px;
}
}
Best Practices for Modern Web Development
Start with Logical Properties
When writing new CSS, default to using logical properties instead of physical ones. This future-proofs your code and reduces the need for overrides when supporting different writing modes:
/* Instead of this */
.element {
margin-top: 1rem;
margin-bottom: 1rem;
padding-left: 1rem;
padding-right: 1rem;
}
/* Use this */
.element {
margin-block: 1rem;
padding-inline: 1rem;
}
Combine with Logical Shorthands
For maximum efficiency, use other logical property shorthands alongside inset-block:
.element {
margin-block: 1rem;
padding-inline: 1rem;
inset-block: auto 2rem;
inset-inline: 1rem;
}
Performance Tips
- Use
transformfor animations instead of modifying inset values - Avoid layout thrashing when animating with JavaScript
- Batch DOM reads and writes when using inset-block in scripts
Accessibility Considerations
When using inset-block for positioning, ensure your layouts remain accessible:
- Manage focus appropriately for positioned elements like modals
- Respect user preferences for reduced motion
- Maintain logical reading order for screen reader users
Integration with Next.js
CSS Modules
With CSS Modules in Next.js, you can use inset-block just as you would in regular CSS:
/* components/Modal.module.css */
.modal {
position: fixed;
inset-block: 50%;
inset-inline: 50%;
transform: translate(-50%, -50%);
background: white;
border-radius: 8px;
}
.overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.5);
}
CSS Variables for Theming
Use CSS variables to create themeable component systems:
:root {
--spacing-unit: 1rem;
--overlay-inset-block: 2rem;
}
.overlay {
position: fixed;
inset-block: var(--overlay-inset-block);
inset-inline: var(--spacing-unit);
}
Styled Components
When using CSS-in-JS solutions like styled-components, inset-block works consistently:
const ModalOverlay = styled.div`
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
`;
const ModalContent = styled.div`
position: fixed;
inset-block: 50%;
inset-inline: 50%;
transform: translate(-50%, -50%);
background: white;
padding: 2rem;
border-radius: 8px;
`;
Tailwind CSS
Tailwind CSS supports logical properties through its utilities. You can use arbitrary values for inset-block:
<div class="inset-y-[20px]">...</div>
Or create custom utilities in your Tailwind config for cleaner code.
These integrations demonstrate how inset-block fits seamlessly into modern React and Next.js development workflows.
| Property | Description | Shorthand For |
|---|---|---|
| inset | Sets all four edges | top, right, bottom, left |
| inset-block | Block direction offsets | inset-block-start, inset-block-end |
| inset-inline | Inline direction offsets | inset-inline-start, inset-inline-end |
| inset-block-start | Block start offset | - |
| inset-block-end | Block end offset | - |
| inset-inline-start | Inline start offset | - |
| inset-inline-end | Inline end offset | - |
| Logical Property | horizontal-tb | vertical-rl | vertical-lr |
|---|---|---|---|
| inset-block-start | top | right | left |
| inset-block-end | bottom | left | right |
| inset-inline-start | left | top | top |
| inset-inline-end | right | bottom | bottom |
Frequently Asked Questions
Sources
-
MDN Web Docs - CSS inset-block - Official documentation covering syntax, values, browser support, and formal definitions.
-
CSS-Tricks - inset-block - Practical guide with examples demonstrating how
inset-blockbehaves with different writing modes. -
CSS Logical Properties and Values Level 1 Specification - Official W3C specification defining logical properties and values.
-
W3Schools - CSS inset-block-start property - Educational reference explaining block direction in CSS.
-
2hats Logic - Ultimate CSS Inset Guide - Comprehensive guide covering inset properties for precise element positioning.