0

Can someone please explain the below CSS code:

html:not([dir="rtl"]){
    //some CSS property
}

3 Answers 3

3
html:not([dir="rtl"])

Let's break it down!


html

Selects all html elements (there's most likely only one)...

:not( ... )

... that do not...

[dir="rtl"]

... have the attribute dir set to "rtl".

So, to sum it up, it selects all html elements that do not have dir set to "rtl". Example:

<html>  <!-- Would match! -->

<html lang="en">  <!-- Would match! -->

<html dir>  <!-- Would match! -->

<html dir="ltr">  <!-- Would match! -->

<html dir="rtl">  <!-- Would NOT match! -->
Sign up to request clarification or add additional context in comments.

4 Comments

It has only to do with html tag. Other tags won't be affected. Correct?
Correct! If you did *:not([dir="rtl"]) it would match any tag that had dir="rtl" (because * is the universal selector)
it would match any tag that did / 'did not' have dir="rtl" ??
Oh, my bad! That did not have dir="rtl"
1

That is :not() pseudo-class and inside is attribute selector, so it will select html if it doesn't have dir="rtl" attribute which is text-direction set right to left.

Comments

1

It will select all html tags that don't have the attribute dir with value rtl.

Each part:

Select html tag: html

Select the inverse: :not()

Select an attribute with specific value: [attribute="value"]

1 Comment

By everything, you mean only html tags. Correct?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.