- Services
- Case Studies
- Technologies
- NextJs development
- Flutter development
- NodeJs development
- ReactJs development
- About
- Contact
- Tools
- Blogs
- FAQ
Understanding CSS max-block-size for Responsive Design
Useful for responsive designs with horizontal/vertical text.
Options include length, percentage, fit-content.
max-block-size
Baseline
The max-block-size
property is well-established and widely supported across many devices and browser versions. It has been available since September 2021, making it a reliable feature for web developers and designers. This broad compatibility ensures that your web designs will work consistently across different platforms and browsers.
Description
The max-block-size
CSS property sets the maximum size of an element in the direction opposite to the writing direction. This direction is determined by the writing-mode
property. If the writing direction is horizontal, max-block-size
acts like max-height
. If the writing direction is vertical, max-block-size
acts like max-width
.
This property is especially useful for creating responsive and adaptable web designs. It allows you to control the maximum size of elements based on the direction of the text content, ensuring that your layouts look good regardless of the writing mode.
Syntax
The syntax for the max-block-size
CSS property is straightforward and similar to other CSS size properties. Here is the basic syntax:
Explanation of Syntax
<length>
values: Specifies the maximum size as an absolute value, such as pixels (px) or ems (em).<percentage>
values: Sets the maximum size as a percentage of the containing block’s size in the block axis.- Keyword values:
none
: No limit on the size of the box.max-content
: The intrinsic preferred maximum size.min-content
: The intrinsic minimum maximum size.fit-content
: Uses the available space, but not more thanmax-content
.fit-content(<length-percentage>)
: Uses thefit-content
formula with the available space replaced by the specified argument.
- Global values:
inherit
: Inherits the value from the parent element.initial
: Sets the property to its initial value.revert
: Rolls back the property to the user agent’s default.revert-layer
: Rolls back the property to the value set at the previous cascade layer.unset
: Resets the property to its natural value, which means it acts asinherit
if the property is inherited andinitial
if it is not.
Anchor Size Values
anchor-size()
: This function can be used to set the maximum size based on the size of another element or anchor.
Calculated Values
calc()
: Allows you to calculate the maximum size using a combination of other values.
Formal definition
The max-block-size
property in CSS is formally defined with specific characteristics and behaviors. Here is a detailed breakdown of its formal definition:
Initial Value
none
: By default, themax-block-size
property is set tonone
, which means there is no limit on the size of the box.
Applies to
- Same as [
width
]WebsiteUrl and [height
]WebsiteUrl: Themax-block-size
property applies to the same elements as thewidth
andheight
properties.
Inherited
- No: The
max-block-size
property is not inherited from the parent element. Each element must have its ownmax-block-size
defined.
Percentages
- Block-size of containing block: When using percentage values, the
max-block-size
is calculated as a percentage of the containing block’s size in the block axis.
Computed Value
- Same as [
max-width
]WebsiteUrl and [max-height
]WebsiteUrl: The computed value ofmax-block-size
is determined similarly to themax-width
andmax-height
properties.
Animation Type
- Length, percentage, or calc(): The
max-block-size
property can be animated using length, percentage, or calculated values. This allows for smooth transitions and animations based on the maximum size of the element.
Summary
- Initial Value:
none
- Applies to: Same as
width
andheight
- Inherited: No
- Percentages: Block-size of containing block
- Computed Value: Same as
max-width
andmax-height
- Animation Type: Length, percentage, or calc()
Formal syntax
The formal syntax for the max-block-size
property in CSS defines how the property can be specified. This syntax includes the various values and combinations that can be used to set the maximum size of an element in the direction opposite to the writing direction. Here is a detailed breakdown of the formal syntax:
Explanation of Syntax
<length>
values: Specifies the maximum size as an absolute value, such as pixels (px) or ems (em).<percentage>
values: Sets the maximum size as a percentage of the containing block’s size in the block axis.- Keyword values:
none
: No limit on the size of the box.max-content
: The intrinsic preferred maximum size.min-content
: The intrinsic minimum maximum size.fit-content
: Uses the available space, but not more thanmax-content
.fit-content(<length-percentage>)
: Uses thefit-content
formula with the available space replaced by the specified argument.
- Global values:
inherit
: Inherits the value from the parent element.initial
: Sets the property to its initial value.revert
: Rolls back the property to the user agent’s default.revert-layer
: Rolls back the property to the value set at the previous cascade layer.unset
: Resets the property to its natural value, which means it acts asinherit
if the property is inherited andinitial
if it is not.
Anchor Size Values
anchor-size()
: This function can be used to set the maximum size based on the size of another element or anchor.
Calculated Values
calc()
: Allows you to calculate the maximum size using a combination of other values.
How writing-mode affects directionality
The writing-mode
property in CSS determines the direction of text flow in a block. This property can significantly impact how the max-block-size
property behaves. Depending on the value of writing-mode
, max-block-size
will map to either max-height
or max-width
.
Understanding Writing Modes
The writing-mode
property can have various values that dictate the text direction:
horizontal-tb
: Text flows horizontally from left to right, with lines stacking vertically (top to bottom).vertical-rl
: Text flows vertically from top to bottom, with lines stacking horizontally from right to left.vertical-lr
: Text flows vertically from top to bottom, with lines stacking horizontally from left to right.sideways-rl
: Text is rotated 90 degrees clockwise and flows vertically, with lines stacking horizontally from right to left.sideways-lr
: Text is rotated 90 degrees counter-clockwise and flows vertically, with lines stacking horizontally from left to right.
Impact on max-block-size
The max-block-size
property will behave differently based on these writing modes:
Values of writing-mode | max-block-size is equivalent to |
---|---|
horizontal-tb , lr , lr-tb , rl , rb , rb-rl | max-height |
vertical-rl , vertical-lr , sideways-rl , sideways-lr , tb , tb-rl | max-width |
Example Scenarios
- Horizontal Writing Mode (
horizontal-tb
):max-block-size
acts likemax-height
.- Example: A block of text with horizontal writing mode and a
max-block-size
of 300px will have a maximum height of 300px.
- Vertical Writing Mode (
vertical-rl
):max-block-size
acts likemax-width
.- Example: A block of text with vertical writing mode and a
max-block-size
of 300px will have a maximum width of 300px.
Practical Usage
Using max-block-size
appropriately based on the writing mode ensures that your layout adapts seamlessly to different text orientations. This is particularly useful for multilingual websites or applications that need to support various writing systems.
Notes
- Deprecated Values: The
writing-mode
valuessideways-lr
andsideways-rl
were removed from the CSS Writing Modes Level 3 specification and may be restored in Level 4. - HTML Contexts: The writing modes
lr
,lr-tb
,rl
,rb
, andrb-tl
are no longer allowed in HTML contexts; they may only be used in SVG 1.x contexts.
Examples
Setting max-block-size with different units
HTML
CSS
Result
This example shows how the max-block-size
property can be used with different units to control the maximum size of an element. Using pixels, ems, and percentages allows for precise control over the layout and ensures that your designs are flexible and responsive.
Setting max-block-size with fit-content
HTML
CSS
Result
This example demonstrates how the fit-content
value can be used to set the max-block-size
property. The fit-content
value ensures that the element uses the available space but does not exceed the specified maximum size. This is useful for creating flexible and adaptable layouts.
Setting max-block-size with horizontal and vertical text
HTML
CSS
Result
This example demonstrates how the max-block-size
property adapts to different writing modes. In the horizontal writing mode (horizontal-tb
), max-block-size
acts like max-height
, limiting the height of the text block to 160 pixels. In the vertical writing mode (vertical-rl
), max-block-size
acts like max-width
, limiting the width of the text block to 160 pixels.
By setting the max-block-size
property, you ensure that the text blocks do not exceed the specified maximum size, regardless of the writing mode. This is particularly useful for creating responsive designs that adapt to different text orientations and content sizes.
Specifications
The max-block-size
property is defined in several CSS specifications that outline its behavior and usage. These specifications provide the formal definitions and guidelines for implementing this property in web browsers.
CSS Logical Properties and Values Level 1
- Specification Link: [CSS Logical Properties and Values Level 1]WebsiteUrl
CSS Box Sizing Module Level 4
- Specification Link: [CSS Box Sizing Module Level 4]WebsiteUrl
These specifications ensure that the max-block-size
property is thoroughly defined and can be implemented consistently across different web browsers. By adhering to these specifications, web developers can create reliable and responsive designs that work seamlessly across various devices and platforms.
Browser compatibility
The max-block-size
property is well-supported across many modern web browsers, ensuring that your web designs will work consistently across different platforms and devices. Below is a summary of the browser compatibility for this property:
Browser Support
- Chrome: WebsiteUrl
- Firefox: WebsiteUrl
- Safari: WebsiteUrl
- Edge: WebsiteUrl
- Opera: WebsiteUrl
By understanding and using these examples and specifications, you can effectively implement the max-block-size
property in your web projects to create responsive and adaptable designs.
Browser Compatibility for max-block-size
- Firefox: Supports
max-block-size
from version 41. - Google Chrome: Supports
max-block-size
from version 57. - Microsoft Edge: Supports
max-block-size
from version 79. - Opera: Supports
max-block-size
from version 44. - Safari: Supports
max-block-size
from version 12.1.
Compatibility Table
Browser | Minimum Version |
---|---|
Firefox | 41 |
Google Chrome | 57 |
Microsoft Edge | 79 |
Opera | 44 |
Safari | 12.1 |
Notes
- Firefox 41: Full support for
max-block-size
. - Google Chrome 57: Full support for
max-block-size
. - Microsoft Edge 79: Full support for
max-block-size
. - Opera 44: Full support for
max-block-size
. - Safari 12.1: Full support for
max-block-size
.
This broad compatibility means you can safely use max-block-size
in your web projects, knowing it works across a wide range of browsers.
Additional Resources
For detailed browser compatibility, check out:
- [MDN Web Docs -
max-block-size
Browser Compatibility]WebsiteUrl - [Can I Use - max-block-size]WebsiteUrl
Related Properties and Resources
To better understand and use max-block-size
, check out these related properties and resources:
Related Properties
max-width
andmax-height
:- These properties control the maximum width and height of an element.
- [MDN Web Docs -
max-width
]WebsiteUrl - [MDN Web Docs -
max-height
]WebsiteUrl
max-inline-size
:- Sets the maximum size of an element in the direction of the writing mode.
- [MDN Web Docs -
max-inline-size
]WebsiteUrl
writing-mode
:- Defines the direction of text flow in a block, affecting
max-block-size
. - [MDN Web Docs -
writing-mode
]WebsiteUrl
- Defines the direction of text flow in a block, affecting
Additional Resources
- CSS Logical Properties and Values Level 1:
- Introduces logical properties and values, including
max-block-size
. - [CSS Logical Properties and Values Level 1]WebsiteUrl
- Introduces logical properties and values, including
- CSS Box Sizing Module Level 4:
- Defines sizing properties, ensuring consistency across implementations.
- [CSS Box Sizing Module Level 4]WebsiteUrl
- MDN Web Docs:
- Extensive documentation on CSS properties, including
max-block-size
. - [MDN Web Docs - CSS]WebsiteUrl
- Extensive documentation on CSS properties, including
- Can I Use:
- Detailed information on browser compatibility for web technologies.
- [Can I Use - max-block-size]WebsiteUrl
By exploring these resources, you can deepen your understanding of max-block-size
and create more flexible, responsive web designs.
Talk with CEO
We'll be right here with you every step of the way.
We'll be here, prepared to commence this promising collaboration.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.