Tsallaka zuwa abun ciki
Justice Tech School

Attribute Selectors

Square brackets match attributes. [title] matches elements that have the attribute, [type="text"] matches an exact value, [href^="https"] matches values that start with a string, [href$=".pdf"] matches values that end with it, and [class*="btn"] matches values containing it.

They are handy for styling form controls by type and for marking external links without adding classes.

Example
<style>
  input[type="text"] { border: 2px solid teal; padding: 6px; }
  input[type="password"] { border: 2px solid crimson; padding: 6px; }
  a[href$=".pdf"]::after { content: " (PDF)"; color: gray; }
</style>
<input type="text" placeholder="Name"><br><br>
<input type="password" placeholder="Secret"><br><br>
<a href="guide.pdf">Download guide</a>

Exercise

Select inputs whose type is "email".

input[type=] {
  border: 1px solid blue;
}

Quiz Test

What does [href$=".pdf"] match?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.