--- title: انتخابگر ویژگی slug: Web/CSS/انتخابگرـویژگی translation_of: Web/CSS/Attribute_selectors ---
{{CSSRef}}

انتخابگر ویژگی بر اساس وجود ویژگی یا مقدار ویژگی انتخاب می‌کند.

/* را داشته باشند title که ویژگی <a> عنصرهای */
a[title] {
  color: purple;
}

/* باشد "https://example.org" آن برابر با  href که ویژگی  <a> عنصرهای */
a[href="https://example.org"] {
  color: green;
}

/* باشد "example" آن در بردارنده‌ی href که ویژگی <a> عنصرهای */
a[href*="example"] {
  font-size: 2em;
}

/* به پایان رسیده باشد ".org" آن با href که ویژگی <a> عنصرهای */
a[href$=".org"] {
  font-style: italic;
}
[attr]
Represents elements with an attribute name of attr.
[attr=value]
Represents elements with an attribute name of attr whose value is exactly value.
[attr~=value]
Represents elements with an attribute name of attr whose value is a whitespace-separated list of words, one of which is exactly value.
[attr|=value]
Represents elements with an attribute name of attr whose value can be exactly value or can begin with value immediately followed by a hyphen, - (U+002D). It is often used for language subcode matches.
[attr^=value]
Represents elements with an attribute name of attr whose value is prefixed (preceded) by value.
[attr$=value]
Represents elements with an attribute name of attr whose value is suffixed (followed) by value.
[attr*=value]
Represents elements with an attribute name of attr whose value contains at least one occurrence of value within the string.
[attr operator value i]
Adding an i (or I) before the closing bracket causes the value to be compared case-insensitively (for characters within the ASCII range).

Examples

CSS

a {
  color: blue;
}

/* Internal links, beginning with "#" */
a[href^="#"] {
  background-color: gold;
}

/* Links with "example" anywhere in the URL */
a[href*="example"] {
  background-color: silver;
}

/* Links with "insensitive" anywhere in the URL,
   regardless of capitalization */
a[href*="insensitive" i] {
  color: cyan;
}

/* Links that end in ".org" */
a[href$=".org"] {
  color: red;
}

HTML

<ul>
  <li><a href="#internal">Internal link</a></li>
  <li><a href="http://example.com">Example link</a></li>
  <li><a href="#InSensitive">Insensitive internal link</a></li>
  <li><a href="http://example.org">Example org link</a></li>
</ul>

Result

{{EmbedLiveSample('Links')}}

Languages

CSS

/* All divs with a `lang` attribute are bold. */
div[lang] {
  font-weight: bold;
}

/* All divs in US English are blue. */
div[lang~="en-us"] {
  color: blue;
}

/* All divs in Portuguese are green. */
div[lang="pt"] {
  color: green;
}

/* All divs in Chinese are red, whether
   simplified (zh-CN) or traditional (zh-TW). */
div[lang|="zh"] {
  color: red;
}

/* All divs with a Traditional Chinese
   `data-lang` are purple. */
/* Note: You could also use hyphenated attributes
   without double quotes */
div[data-lang="zh-TW"] {
  color: purple;
}

HTML

<div lang="en-us en-gb en-au en-nz">Hello World!</div>
<div lang="pt">Olá Mundo!</div>
<div lang="zh-CN">世界您好!</div>
<div lang="zh-TW">世界您好!</div>
<div data-lang="zh-TW">?世界您好!</div>

Result

{{EmbedLiveSample('Languages')}}

Specifications

Specification Status Comment
{{SpecName('CSS4 Selectors', '#attribute-selectors', 'attribute selectors')}} {{Spec2('CSS4 Selectors')}} Adds modifier for ASCII case-insensitive attribute value selection
{{SpecName('CSS3 Selectors', '#attribute-selectors', 'attribute selectors')}} {{Spec2('CSS3 Selectors')}}  
{{SpecName('CSS2.1', 'selector.html#attribute-selectors', 'attribute selectors')}} {{Spec2('CSS2.1')}} Initial definition

Browser compatibility

{{Compat("css.selectors.attribute")}}

See also