# Problem with div id, or it wont make background gray

**URL:** <https://forum.freecodecamp.org/t/problem-with-div-id-or-it-wont-make-background-gray/502592>\
**Category:** Curriculum Help\
**Tags:** html, css\
**Created:** [March 28, 2022, 7:58pm UTC](https://forum.freecodecamp.org/t/problem-with-div-id-or-it-wont-make-background-gray/502592 "2022-03-28T19:58:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![filip1](https://avatars.discourse-cdn.com/v4/letter/f/f14d63/32.png) [@filip1](https://forum.freecodecamp.org/u/filip1)\
**Post date:** [March 28, 2022, 7:58pm UTC](https://forum.freecodecamp.org/t/problem-with-div-id-or-it-wont-make-background-gray/502592/1 "2022-03-28T19:58:29Z")

</div>

hi,  
I used to work in notepad and there I make this:

```auto
<div id="div">

<h1>this is heading</h1>
<p>this is paragraph</p>

</div>
<style>

#div{background-color: gray;}

</style>

```

when I open it in browser it makes div gray, heading and paragraph together, but now when I am using A pen I do the same:

```auto
<div id="background color">
<h1=>Dr. Norman Borlaug</h1>
<p>The man who saved a bilion lives</p>
  </div>
#background color {gray
}

```

and it wont work, can anyone help, thank you

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [March 28, 2022, 7:59pm UTC](https://forum.freecodecamp.org/t/problem-with-div-id-or-it-wont-make-background-gray/502592/2 "2022-03-28T19:59:11Z")

</div>

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (`</>`) to add backticks around text.

 ![Pre-formatted-text](https://global.discourse-cdn.com/freecodecamp/original/3X/1/b/1b18854f1059217f29370444396145cc3a0cd8ae.gif)

See [this post](https://forum.freecodecamp.org/t/forum-code-formatting/25574) to find the backtick on your keyboard.  
**Note:** Backticks (`) are not single quotes (’).

---

<div class="post-metadata">

**Author:** ![ArielLeslie](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/arielleslie/32/264841_2.png) [@ArielLeslie](https://forum.freecodecamp.org/u/ArielLeslie)\
**Post date:** [March 28, 2022, 8:02pm UTC](https://forum.freecodecamp.org/t/problem-with-div-id-or-it-wont-make-background-gray/502592/3 "2022-03-28T20:02:05Z")

</div>

I’m seeing a bunch of issues with your second code snippet:

> [@filip1](#):
>
> `<div id="background color">`

An id cannot have a space in it.

> [@filip1](#):
>
> `<h1=>Dr. Norman Borlaug</h1>`

This is a malformed html tag.

> [@filip1](#):
>
> ```auto
> #background color {gray
> }
> 
> ```

This is not valid CSS.  
Is this just in your HTML? Or is it in a CSS section?  
As mentioned, identifiers can’t have spaces.

---

<div class="post-metadata">

**Author:** ![miladvalizadeh2003](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/miladvalizadeh2003/32/211010_2.png) [@miladvalizadeh2003](https://forum.freecodecamp.org/u/miladvalizadeh2003)\
**Post date:** [March 28, 2022, 8:13pm UTC](https://forum.freecodecamp.org/t/problem-with-div-id-or-it-wont-make-background-gray/502592/4 "2022-03-28T20:13:52Z")

</div>

The name of your id can’t contain spaces in it. Try using “background-color” or “background\_color” instead.

```auto
<style>

#background-color {
  background-color: gray;
}

</style>

<div id="background-color">
some code here...
</div>

```

---

<div class="post-metadata">

**Author:** ![filip1](https://avatars.discourse-cdn.com/v4/letter/f/f14d63/32.png) [@filip1](https://forum.freecodecamp.org/u/filip1)\
**Post date:** [March 28, 2022, 8:16pm UTC](https://forum.freecodecamp.org/t/problem-with-div-id-or-it-wont-make-background-gray/502592/5 "2022-03-28T20:16:46Z")

</div>

thank you! this solved a problem

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [September 27, 2022, 8:17am UTC](https://forum.freecodecamp.org/t/problem-with-div-id-or-it-wont-make-background-gray/502592/6 "2022-09-27T08:17:44Z")

</div>

Closed on September 27, 2022, 8:17am UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
