Selector by attribute value
The attribute value selector allows you to select elements based on whether they have a specific attribute or its value and apply the desired style to them.
Example
Let's select the input tag, which has
the type attribute value of text,
and give it a blue background color:
<p>
<label>Enter text</label>
<input type="text">
</p>
<p>
<label>Enter number</label>
<input type="number">
</p>
input[type="text"] {
background-color: #C2DDFD;
}
:
See also
-
an attribute selector
that searches for an element by attribute name -
an attribute selector
that searches for an element based on the start of an attribute value -
an attribute selector
that searches for an element based on the end of an attribute value -
an attribute selector
that searches for an element by text in an attribute value -
an attribute selector
that searches for an element based on one of attribute values -
an attribute selector
that searches for an element by a hyphen in an attribute value -
the child selector
that allows you to select elements by direct nesting -
the descendant selector,
that allows you to select an element by its parent -
the adjacent sibling selector
that allows you to select an element by its sibling -
the general sibling selector
that allows you to select elements after a given -
the universal selector
that allows you to select all elements