- Services
- Case Studies
- Technologies
- NextJs development
- Flutter development
- NodeJs development
- ReactJs development
- About
- Contact
- Tools
- Blogs
- FAQ
CSS shape-margin Property Enhance Layouts with Precision
Discover how to use it to set margins for CSS shapes, explore its various options, and enhance your web layouts.
Introduction
The shape-margin
property in CSS is a handy tool for web designers. It lets you set a margin around a shape created with the shape-outside
property. This feature has been around since January 2020 and works on many devices and browsers. By adjusting the space between the shape and surrounding content, shape-margin
makes your web designs more flexible and visually appealing.
Specification
The shape-margin
property is part of the CSS Shapes Module Level 1. This module allows you to define geometric shapes and use them to wrap content around.
Description
The shape-margin
property sets a margin for a shape created with the shape-outside
property. This margin adjusts the space between the shape and the surrounding content. It’s great for creating dynamic and visually appealing designs.
Syntax
The shape-margin
property is easy to use. It accepts lengths, percentages, and global values. Here’s the basic syntax:
Length Values
You can set the margin using specific lengths, like pixels (px
) or millimeters (mm
).
Percentage Values
You can also set the margin as a percentage of the width of the element’s containing block.
Global Values
The shape-margin
property supports global values like inherit
, initial
, revert
, revert-layer
, and unset
.
Values
The shape-margin
property accepts a range of values, including lengths, percentages, and global values.
Length Values
<length>
: Sets the margin to a specific length, like pixels (px
) or millimeters (mm
).
Percentage Values
<percentage>
: Sets the margin as a percentage of the width of the element’s containing block.
Global Values
inherit
: Inherits the value from the parent element.initial
: Sets the property to its initial value, which is0
.revert
: Reverts the property to the user agent’s default stylesheet value.revert-layer
: Reverts the property to the value specified in the previous cascade layer.unset
: Resets the property to its natural value, which means it acts asinitial
if the property is not inherited, orinherit
if it is.
Formal Definition
The shape-margin
property is formally defined with specific characteristics:
- Initial Value:
0
- Applies To: Floats
- Inherited: No
- Percentages: Refer to the width of the containing block
- Computed Value: As specified, but with relative lengths converted into absolute lengths
- Animation Type: A length, percentage, or
calc()
Formal Syntax
The formal syntax for the shape-margin
property is:
Where <length-percentage>
can be:
<length>
: A length value (e.g.,px
,mm
)<percentage>
: A percentage value
Browser Compatibility
The shape-margin
property is widely supported across various browsers:
- Google Chrome 37
- Firefox 62
- Safari 10.1
- Opera 24
See Also
- [CSS Shapes]WebsiteUrl
- [Overview of CSS Shapes]WebsiteUrl
- [
shape-outside
]WebsiteUrl - [
shape-image-threshold
]WebsiteUrl - [
<basic-shape>
]WebsiteUrl
Examples
Adding a Margin to a Polygon
HTML
CSS
Adding a Margin to a Circle
HTML
CSS
Adding a Margin to an Ellipse
HTML
CSS
Using shape-margin
for Spacing Around Shapes
HTML
CSS
These examples show how to use the shape-margin
property to add margins around different shapes, enhancing the layout and readability of your content.
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.