It is possible to style HTML elements that have specific attributes or attribute values. The [attribute] selector is used to select elements with a specified attribute. The following example selects all <a> elements with a target attribute:
HTML file: | Displayed by browser: |
---|---|
<style>
a[target] { background-color: yellow; } </style> <body> <p>Any links with target attribute gets a yellow background:</p> <p><a href="http://www.w3schools.com">W3 Schools</a></p> <p><a href="http://www.disney.com" target="_blank">Disney Website</a></p> <p><a href="http://www.wikipedia.org" target="_top">Wikipedia</a></p> </body> |
Any links with target attribute gets a yellow background: |