Skip to main content
D
CSS
CSS Attribute Selectors

CSS Attribute Selectors

CSS attribute selectors target elements by their HTML attributes.

Read Time
5 min read
Difficulty
Beginner
Last Updated
Jun 15, 2026
Version
v1.0.0

Introduction

CSS styles elements based on the specific attributes they carry. Developers can target all links that open in a new tab or all input fields of a certain type. This avoids cluttering the HTML with extra class names.

Example

Example
1/* this targets target attributes */
2a[target="_blank"] {
3  background-color: yellow;
4}
5
6input[type="text"] {
7  border: 1px solid black;
8}

Key Points

  • Square brackets define an attribute selector.
  • You can target the mere presence of an attribute.
  • You can target an exact attribute value.
  • You can target partial attribute values.

Up Next

Continue your journey with the next topic.

Go to CSS Flexbox