Margin and Padding Control (margin, padding)


  Controlling margins and padding in CSS is essential for the layout of elements on a page.


Syntax


  Controlling margins and padding in CSS is crucial for the layout of elements on a page.

  - Margins create space around elements, and can be defined individually as:
    margin, margin-top, margin-right, margin-bottom, and margin-left.

  - Padding controls the space between an element's content and its border, and can also be specified as:
    padding, padding-top, padding-right, padding-bottom, and padding-left.


Examples include:
  margin: 20px;,
  padding: 15px;


Purpose


These properties help control the layout of elements:


  • Increase or decrease the space around elements.
  • Improve the readability and overall design of the page.
  • Ensure elements do not overlap.


Exercises



The rest of the content is available only for registered and premium users!



Which of the following is a CSS property to apply a margin?