# freeCodeCamp Challenge Guide: Add a Negative Margin to an Element

**URL:** <https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-add-a-negative-margin-to-an-element/16166>\
**Category:** freeCodeCamp Contributors\
**Tags:** guide\
**Created:** [July 1, 2016, 4:40am UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-add-a-negative-margin-to-an-element/16166 "2016-07-01T04:40:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![camperbot](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/camperbot/32/18364_2.png) [@camperbot](https://forum.freecodecamp.org/u/camperbot)\
**Post date:** [July 1, 2016, 4:40am UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-add-a-negative-margin-to-an-element/16166/1 "2016-07-01T04:40:54Z")

</div>

# [Add a Negative Margin to an Element](https://www.freecodecamp.org/learn/responsive-web-design/basic-css/add-a-negative-margin-to-an-element)

* * *

## Problem Explanation

Margin is the spacing between the border of an element and other elements on the page.

•There is spacing from the top, right, bottom, and left.

•The number is in [css units](https://www.tutorialspoint.com/css/css_measurement_units.htm)

For example, to adjust the margin of an element to be negative you could use:

```css
.example {
margin: -10px;
}

```

**To adjust the padding of an individual element** use:  
padding: `-10`px;

[You can find out much more about negative margins here](https://www.smashingmagazine.com/2009/07/the-definitive-guide-to-using-negative-margins/)

Good luck!

---

<div class="post-metadata">

**Author:** ![zahidza1](https://avatars.discourse-cdn.com/v4/letter/z/bbe5ce/32.png) [@zahidza1](https://forum.freecodecamp.org/u/zahidza1)\
**Post date:** [July 5, 2017, 5:36pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-add-a-negative-margin-to-an-element/16166/2 "2017-07-05T17:36:15Z")

</div>

.I changed it 20 px but still not working  
green-box {  
background-color: green;  
padding: 20px;  
margin: -15px;

---

<div class="post-metadata">

**Author:** ![anon52159105](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@anon52159105](https://forum.freecodecamp.org/u/anon52159105)\
**Post date:** [August 6, 2017, 11:20pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-add-a-negative-margin-to-an-element/16166/3 "2017-08-06T23:20:28Z")

</div>

Closed on August 6, 2017, 11:20pm UTC



---

<div class="post-metadata">

**Author:** ![camperbot](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/camperbot/32/18364_2.png) [@camperbot](https://forum.freecodecamp.org/u/camperbot)\
**Post date:** [August 10, 2019, 1:21am UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-add-a-negative-margin-to-an-element/16166/4 "2019-08-10T01:21:19Z")

</div>

Opened on August 10, 2019, 1:21am UTC



---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 8, 2025, 4:03pm UTC](https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-add-a-negative-margin-to-an-element/16166/5 "2025-01-08T16:03:01Z")

</div>

Closed on January 8, 2025, 4:03pm UTC


