Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

Attribute Selector

We’ve added a footer to the bottom of the page, with a link to the source of our text and a link back to the top of the page. The first link opens in a new tab, because it has the attribute target="_blank":

<footer>
	<p>Source: <a href="https://en.wikipedia.org/wiki/Cat" target="_blank">Wikipedia</a></p>
	<p><a href="#title">Back to top</a></p>
</footer>

Elements can also be selected by their attributes. An attribute selector is written in square brackets:

  • [target] selects the elements that have the attribute target, whatever its value,
  • [target="_blank"] selects the elements whose attribute target has exactly the value _blank.

You can write a type selector right before the brackets: a[target="_blank"] selects the a elements with the attribute target="_blank", that is, the links that open in a new tab. It’s good to let visitors know about such links, so let’s make them look different.

Instructions

  1. 1

    Create a rule for a[target="_blank"] that sets italics: font-style: italic. The link to Wikipedia will be in italics, while the link back to the top stays as it is.

Back

8/17

  1. 1. Rules and Comments
  2. 2. Quiz: Rules
  3. 3. Universal Selector
  4. 4. Type Selector
  5. 5. Class Selector
  6. 6. ID Selector
  7. 7. Quiz: Class or ID?
  8. 8. Attribute Selector
  9. 9. Pseudo-classes
  10. 10. Grouping Selectors
  11. 11. Chaining Selectors
  12. 12. Selecting Descendants
  13. 13. Selecting Children
  14. 14. The Cascade
  15. 15. Specificity
  16. 16. Inheritance
  17. 17. Summary
Next

Try it yourself

Do this exercise right here in your browser. No account needed.