# Can I style an id/class with elements in the same selector?

**URL:** <https://forum.freecodecamp.org/t/can-i-style-an-id-class-with-elements-in-the-same-selector/317304>\
**Category:** General\
**Created:** [September 25, 2019, 8:37pm UTC](https://forum.freecodecamp.org/t/can-i-style-an-id-class-with-elements-in-the-same-selector/317304 "2019-09-25T20:37:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![El\_Escandalo](https://avatars.discourse-cdn.com/v4/letter/e/d6d6ee/32.png) [@El\_Escandalo](https://forum.freecodecamp.org/u/El_Escandalo)\
**Post date:** [September 25, 2019, 8:37pm UTC](https://forum.freecodecamp.org/t/can-i-style-an-id-class-with-elements-in-the-same-selector/317304/1 "2019-09-25T20:37:11Z")

</div>

If you want to apply the same style attributes to an `id` or `class` as are being applied to elements, is it possible to group them into the same selector?

Here’s my HTML:

```auto
<section id="contact">
  <div>
    <h2>Hit me up yo</h2>
    <p>I won't bite:</p>
  </div>
  <br>

  <div class="contact-link">
    <a id="profile-link" href="https://codepen.io/El_Escandalo" target="_blank">
      Codepen</a>
  </div>
</section>

```

So my question is, could I somehow group the `class="contact-link"` or `id="profile-link"` into the same selector as I’ve grouped elements like this?

```auto
#contact h2,p,.contact-link {
  margin: 0px;
}

```

or

```auto
#contact h2,p,#profile-link {
  margin: 0px;
}

```

I don’t think these ^^^ are working, I’m just wondering if there is a way to do it that would work? Again, I just want to apply the same style to the contact-link as I’m applying to the `h2` and `p` elements. Thank you!

---

<div class="post-metadata">

**Author:** ![daspinola](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/daspinola/32/123787_2.png) [@daspinola](https://forum.freecodecamp.org/u/daspinola)\
**Post date:** [September 25, 2019, 9:36pm UTC](https://forum.freecodecamp.org/t/can-i-style-an-id-class-with-elements-in-the-same-selector/317304/2 "2019-09-25T21:36:24Z")

</div>

Yes, both your examples would work and it is usually organized for readability like so:

```css
#contact h2,
p,
.contact-link {
  margin: 0px;
}

```

What that means is “every `h2` inside of `#contact` will have no margin, every `p` and every `.contact-link` will have also no margin, doesn’t matter if they are inside `#contact` or not”

To apply to only elements inside `#contact` you just do like so:

```css
#contact h2,
#contact p,
#contact .contact-link {
  margin: 0px;
}

```

---

<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 17, 2021, 9:28am UTC](https://forum.freecodecamp.org/t/can-i-style-an-id-class-with-elements-in-the-same-selector/317304/3 "2021-01-17T09:28:05Z")

</div>

Closed on January 17, 2021, 9:28am UTC


