How to select elements with a specified attribute with CSS


To select elements with an attribute, use the CSS [attribute] selector.

For example, alt attribute or a target attribute, etc.

You can try to run the following code to implement the CSS[attribute] selector,

Example

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         img[alt] {
            border: 3px solid orange;
         }
      </style>
   </head>
   <body>
      <img src = "https://www.tutorialspoint.com/videotutorials/images/tutor_connect_home.jpg" height="200" width="200">
      <img src = "https://www.tutorialspoint.com/videotutorials/images/tutorial_library_home.jpg" height="200" width="200" alt="Tutorials Library">
   </body>
</html>

Updated on: 23-Jun-2020

126 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements