Selecting Elements by Type

You can select all of the instances of an element by specifying the element type as the selector. a select all of the a elements.

 
<!DOCTYPE HTML> 
<html> 
    <head> 
    <title>Example</title> 
        <style type="text/css"> 
        a { 
            border: thin black solid; 
            padding: 4px; 
        } 
        </style> 
    </head> 
    <body> 
        <a href="http://java2s.com">Visit the java2s.com</a> 
        <p>I like <span>HTML</span> and CSS.</p> 
        <a href="http://w3c.org">W3C website</a> 
    </body> 
</html>
  
Click to view the demo

The following code applies a style to multiple element types by separating the types with a comma.

 
<!DOCTYPE HTML> 
<html> 
    <head> 
        <title>Example</title> 
        <style type="text/css"> 
        a,p { 
            border: thin black solid; 
            padding: 4px; 
        } 
        </style> 
    </head> 
    <body> 
        <a href="http://java2s.com">Visit the java2s.com</a> 
        <p>I like <span>HTML</span> and CSS.</p> 
        <a href="http://w3c.org">W3C website</a> 
    </body> 
</html>
  
Click to view the demo
Home 
  HTML CSS Book 
    CSS  

Selectors:
  1. Selecting All Elements
  2. Selecting Elements by Type
  3. Selecting Elements by Class
  4. Selecting Elements by ID
  5. Selecting Elements by Attribute
Related: