4

I'm trying to target an elements attribute that contains a colon: :

.someclass[xml:lang="da"]

HTML:

<span class="someclass" xml:lang="da">

Is this possible, does not work with above syntax?

1
  • 2
    Sidenote: xml:lang is only a valid attribute in the html tag. Commented Aug 23, 2016 at 13:38

2 Answers 2

5

CSS has special characters that cannot be applied in class names, so to use them, CSS escapes with a backslash (\)

here is the list of the special characters:

!, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \, ], ^, `, {, |, }, and ~

.someclass[xml\:lang="da"] {
  background: red
}
<span class="someclass" xml:lang="da"> text</span>

Sign up to request clarification or add additional context in comments.

3 Comments

@dippas wasn't me, but perhaps because someone recommends lang over xml:lang?
I was thinking that, I didn't elaborate on that matter given I didn't have enough info from the OP, therefore I just give the info to fix the OP problem
I do recommend lang over xml:lang, but did not downvote this.
4

I do not recommend using the xml:lang attribute. You should use the lang attribute instead. The lang attribute has the special behavior that it can be placed on any element at any level of the hierarchy, and then addressed via the :lang pseudo-class, allowing you to define rules such as

:lang(de) {quotes: "«" "»"; }

and things will "just work".

Consult answers such as this one. Excerpt:

Note however that you may only use the xml:lang attribute if you either have an XML document or also define the lang attribute, and in the latter case they must have the same value. This is because xml:lang is allowed only to ease transition of old XHTML documents.

See also this and this.

Comments

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.