The Dimensions option adds a sophisticated spacing control to your custom widget, allowing users to set values for multiple sides of an element (Top, Right, Bottom, Left) simultaneously. It is primarily used for CSS properties like margin, padding, and border width.
Why would someone use it in a custom widget? #
Use this control whenever you need to manage the spacing or size around or within an element in a structured way. It provides a professional, unified interface – similar to native Elementor widgets – for setting properties like padding and margin, saving you from creating four separate Number controls.
Where This Option Appears #
- In Widget Builder: You add this control in the Content tab.
- In the Elementor Editor:Â Once saved, it appears as the familiar “Dimensions” box with four linked input fields (for Top, Right, Bottom, Left) and a “link” icon to toggle between setting values collectively or individually.
Available Settings #
Here are the configurable settings for the Dimensions control:
Basic Settings #
- Label:Â The name of the control (e.g., “Padding”, “Margin”, “Border Width”).
- Name:Â The unique machine-readable ID (likeÂ
wrapper_padding) for the dynamic shortcode. - Description:Â Optional guiding text.
- Allowed Dimensions:Â Lets you select which sides (Top, Right, Bottom, Left) are available for the user to edit. You can show all four or just specific ones.
- Property Type: An advanced feature. You can leave it as Custom or select a specific CSS property (likeÂ
margin orÂpadding). This may help the builder automatically apply the values to the correct CSS rule. - Size Units: A checkbox list to define which CSS units (PX, %, EM, REM, VH, VW) are available for the user to choose from for each value.
- Default Value:Â Pre-defined values for each of the four sides (Top, Right, Bottom, Left).
Advanced Settings #
- Show Label, Label Block, Responsive Control: Standard options. Responsive Control is essential here, allowing different spacing on different devices.
- Dynamic Support:Â Allows the dimension values to be populated from a dynamic source.
- Frontend Available:Â When enabled, the dimension values are passed to your widget’s JavaScript.
- Separator, Conditions, Control Classes, Selector: Standard advanced options. The Selector is particularly important here to define which CSS element the dimensions should target.
Generated Shortcode #
When you add a Dimensions control with the Name content_padding, Widget Builder generates a shortcode: {{content_padding}}.
- What it represents:Â This shortcode outputs a structured set of values, likely in a shorthand CSS format (e.g.,Â
10px 20px 10px 20px) or as an object containing each side’s value and unit. - Where to use it: Primarily in the CSS Panel, as the value for a spacing-related property.
- CSS Panel:Â
.widget-content { padding: {{content_padding}}; } - The builder’s logic will translate the user’s input (likeÂ
10px,Â5%, etc. for each side) into a valid CSS string for the property.
- CSS Panel:Â
How to Use It: A Practical Example #
Let’s create a “Content Box” widget with fully customizable internal padding.
- In Widget Builder’s Content tab, add a Dimensions control.
- Set the Label toÂ
Box Padding. - In Size Units, enableÂ
PX andÂ% to give users common choices. - In your CSS panel, apply it to the main container:
.custom-content-box {
padding: {{box_padding}};
background-color: #f5f5f5;
} - In the Elementor editor, users will see a dimension box. They can:
- Click the “link” icon to set all four sides to the same value (e.g.,Â
20px). - Unlink it and set each side independently (e.g., Top:Â
30px, Right:Â20px, Bottom:Â30px, Left:Â20px). - Choose different units for different sides (e.g., Top:Â
2%, Right:Â20px).
- Click the “link” icon to set all four sides to the same value (e.g.,Â
Common Use Cases #
- Padding & Margin Management:Â The most frequent use for controlling internal and external spacing.
- Border Width:Â Setting the width for all sides of a border.
- Element Positioning:Â Using in conjunction withÂ
position: absolute forÂtop,Âright,Âbottom,Âleft values (if the Property Type supports it). - Responsive Spacing: Creating complex, device-specific layouts by enabling Responsive Control.
Helpful Tips #
- Choose “Allowed Dimensions” Wisely:Â If your widget only needs vertical (Top/Bottom) padding, you can disable Right and Left for a cleaner interface.
- Link by Default:Â For most use cases, having the sides linked by default is user-friendly. It lets users set a uniform value quickly and unlink only when needed.
- Use with the Correct Property: If you set the Property Type to a specific CSS property likeÂ
padding, ensure your CSS rule uses the same property. For custom use, you might need to map values manually (e.g.,Âtop: {{spacing.TOP}};). - Test Unit Combinations:Â Ensure your widget’s CSS can handle mixed units (likeÂ
px andÂ% together) if you allow multiple units, as this can sometimes break layouts.
The Dimensions control is a fundamental tool for creating flexible, professionally-styled widgets that give users precise control over layout and spacing, mirroring the power of core Elementor design features.