
- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursors
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS Advanced
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Media Types
- CSS - Paged Media
- CSS - Aural Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS3 - Rounded Corner
- CSS3 - Border Images
- CSS3 - Multi Background
- CSS3 - Color
- CSS3 - Gradients
- CSS3 - Shadow
- CSS3 - Text
- CSS3 - Web font
- CSS3 - 2d transform
- CSS3 - 3d transform
- CSS3 - Animation
- CSS3 - Multi columns
- CSS3 - User Interface
- CSS3 - Box Sizing
- CSS Responsive
- CSS - Responsive Web Design
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
The margin Shorthand Property in CSS
The CSS margin shorthand property is used to define the margin area for an element. It sets values in clock-wise direction, i.e. margin-top, margin-right, margin-bottom and then margin-left.
Syntax
The syntax of CSS margin property is as follows −
Selector { margin: /*value*/ }
The following examples illustrate CSS margin shorthand property −
Example
<!DOCTYPE html> <html> <head> <style> div { margin: 7% auto -3% 25%; width: 40px; height: 40px; padding: 0.9rem; box-shadow: inset 0 0 50px turquoise; border: thin solid; } div > div { border-top-right-radius: 100px; border-bottom-right-radius: 500px; border-top-left-radius: 30px; box-shadow: inset 0 0 6px navy; } div > div > div { padding: 0.3em; margin: 2px -40px; box-shadow: inset 0 0 16px orange; border-radius: 50%; } #one { padding: 50px; border-radius: 10px; } </style> </head> <body> <div id="one"> <div> <div></div> </div> </div> </body> </html>
Output
Example
<!DOCTYPE html> <html> <head> <style> article { margin: 2em 1em; background-color: bisque; } span { margin: -23% 83%; border-left: dashed; background-image: linear-gradient(to right, lightgreen, forestgreen); font-size: 1.4em; font-style: italic; } </style> </head> <body> <h2>What is Spring Framework?</h2> <article> Spring framework is an open source Java platform. It was initially written by Rod Johnson and was first released under the Apache 2.0 license in June 2003.<span> Spring is lightweight when it comes to size and transparency. The basic version of Spring framework is around 2MB.</span> </article> </body> </html>
Output
- Related Articles
- The Background Shorthand Property in CSS
- The padding shorthand Property in CSS
- The border Shorthand Property in CSS
- The outline Shorthand Property in CSS
- CSS Animation Shorthand property
- The list-style Shorthand property in CSS
- Animate CSS margin property
- Shorthand property to set the background in CSS
- Animate CSS margin-bottom property
- Animate CSS margin-left property
- Center alignment using the margin property in CSS
- Shorthand property to set the font with CSS
- Shorthand property to set columns with CSS
- Usage of margin property with CSS
- Usage of margin-top property with CSS

Advertisements