# Difference between .class selector and \[attribute~="value"\]

**URL:** <https://forum.freecodecamp.org/t/difference-between-class-selector-and-attribute-value/632827>\
**Category:** General\
**Created:** [August 26, 2023, 1:57am UTC](https://forum.freecodecamp.org/t/difference-between-class-selector-and-attribute-value/632827 "2023-08-26T01:57:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nuno.p](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/nuno.p/32/322116_2.png) [@nuno.p](https://forum.freecodecamp.org/u/nuno.p)\
**Post date:** [August 26, 2023, 1:57am UTC](https://forum.freecodecamp.org/t/difference-between-class-selector-and-attribute-value/632827/1 "2023-08-26T01:57:43Z")

</div>

Hello everyone, thank you for taking the time to help me.

In Step 30 of the Responsive Web Design’s Balance Sheet lesson, it is asked that I create a span[class~=“sr-only”] selector on CSS. However, I’m not really understanding the usage of it.

What would be the difference between:

```auto
span[class~="sr-only"] {
  border: 0;
}

```

and

```auto
.sr-only {
  border: 0;
}

Thanks in advance for answering my noob question. 

```

---

<div class="post-metadata">

**Author:** ![CrlosZgz](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/crloszgz/32/301568_2.png) [@CrlosZgz](https://forum.freecodecamp.org/u/CrlosZgz)\
**Post date:** [August 26, 2023, 8:34am UTC](https://forum.freecodecamp.org/t/difference-between-class-selector-and-attribute-value/632827/2 "2023-08-26T08:34:12Z")

</div>

Hello and welcome.

> [@nuno.p](#):
>
> ```auto
> span[class~="sr-only"] {
> border: 0;
> }
> 
> ```

It only applies to all `span` that includes this class.

> [@nuno.p](#):
>
> ```auto
> .sr-only {
> border: 0;
> }
> 
> ```

It applies to `all elements` with this class.

(and don´t worry. There isn´t `noob asks`. All are interesting)

I hope I can help you.

Grets.

---

<div class="post-metadata">

**Author:** ![nuno.p](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/nuno.p/32/322116_2.png) [@nuno.p](https://forum.freecodecamp.org/u/nuno.p)\
**Post date:** [September 22, 2023, 2:03pm UTC](https://forum.freecodecamp.org/t/difference-between-class-selector-and-attribute-value/632827/3 "2023-09-22T14:03:46Z")

</div>

I see. Thank you for your explanation.

I checked it before, but I couldn’t reply thanking you.

I really appreciate it!

---

<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:** [March 23, 2024, 2:04am UTC](https://forum.freecodecamp.org/t/difference-between-class-selector-and-attribute-value/632827/4 "2024-03-23T02:04:00Z")

</div>

Closed on March 23, 2024, 2:04am UTC

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